How do I convert a DateTime from EST/EDT to GMT but I don't know where the code will be ran (unknown local time zone) and also account for time savings...
Asked
Active
Viewed 1.3k times
2 Answers
14
You want TimeZoneInfo.ConvertTimeToUtc(), which allows you to pass the source time zone info as a parameter. For example:
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime someDateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(someDateTime, est);
I think this will automatically handle daylight-saving time, but you'll want to test it to be sure.

JaredReisinger
- 6,955
- 1
- 22
- 21
-
1sorry i mean eastern time so it could be EST or EDT (Eastern Daylight Time) – Comma Jul 23 '10 at 23:56
-
-
Yup... if you look at the docs, and then look in your registry (where the FindSystemTimeZoneInfoById() does its lookup), you'll see that the "Eastern Standard Time" key has a "Dynamic DST" subkey... so *hopefully* the ConvertTimeToUtc() call will make use of it as needed. – JaredReisinger Jul 24 '10 at 00:15
-
@Comma... "it crashed when i used eastern time"... do you mean you passed "eastern time" to the FindSystemTimeZoneById() method? You should pass "Eastern Standard Time", even though it will sometimes be a daylight-saving-time time. – JaredReisinger Jul 24 '10 at 00:16
-
Microsoft, Why is the timezone called Eastern Standard Time, when Eastern Standard Time is the non-DST version of the all-year name "Eastern Time"? Microsoft fucked up the naming here. so stupid and noone knows how it works because they used the wrong name. blows the mind. – Luke Jul 08 '23 at 22:46