I have a string like this "2012.12.04T08:35:00" that represents a time in the "W. Europe Standard Time" timezone.
Now, I want to convert this properly to a c# DateTime object in UTC time.
What is the proper way to do this?
Home / DeveloperSection / Forums / Convert time in string to UTC time?
I have a string like this "2012.12.04T08:35:00" that represents a time in the "W. Europe Standard Time" timezone.
Now, I want to convert this properly to a c# DateTime object in UTC time.
What is the proper way to do this?
Pravesh Singh
31-Jan-2014Use TimeZoneInfo when converting between specific time zones:
To address your confusion:
DateTime.Parse as used here makes no assumptions about the timezone of the given value. IT stores it with a DateTimeKind of Unspecified.
TimeZoneInfo.ConvertTimeToUtc as used here expects an Unspecified datetime, reads it as if it is in the explicitly specified time zone, and converts it to UTC.