Skip to content

Instantly share code, notes, and snippets.

@killnine
Created October 30, 2014 14:47
Show Gist options
  • Save killnine/3d7a2b8249f560d7c43b to your computer and use it in GitHub Desktop.
Save killnine/3d7a2b8249f560d7c43b to your computer and use it in GitHub Desktop.
//Setup
DateTime localDateTime = new DateTime(2014,10,30,9,6,30,DateTimeKind.Local);
string timeZoneDescription = "Eastern Standard Time";
//Execution
TimeZoneInfo localizedTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneDescription);
var universalTime = TimeZoneInfo.ConvertTimeToUtc(localDateTime, localizedTimeZoneInfo); //This throws an exception, see below!
return universalTime;
/*
Throws exception:
{"The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.\r\nParameter name: sourceTimeZone"}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment