Created
October 30, 2014 14:47
-
-
Save killnine/3d7a2b8249f560d7c43b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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