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...
+2
A:
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
2010-07-23 23:47:59
sorry i mean eastern time so it could be EST or EDT (Eastern Daylight Time)
Comma
2010-07-23 23:56:43
it crashed when i used eastern time
Comma
2010-07-24 00:11:45
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
2010-07-24 00:15: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
2010-07-24 00:16:56
i see. it worked! thanks!
Comma
2010-07-24 00:22:19