views:

99

answers:

4

I have a date format, something similar to:

Mon, Sun, 22 Aug 2010 12:38:33 GMT

How do I convert this to EST format?

Note: I know it can be achieved using TimeZoneinfo, but that is introduced in 3.5, i want to do it 2.0 or any old version.

A: 

EST is probably not a format but an abbreviation of the time zone. I.e. the "manual" way would be to parse the above date and subtract the time zone difference. You should be beware of daylight saving time periods, i.e. you need to check if the above time fits the DST period or not.

Eugene Mayevski 'EldoS Corp
+2  A: 

I guess you have to go the old road of understanding timezones. Your example is though pretty easy.

GMT is UTC with daylight saving changes.
EST is UTC -5hrs with daylight saving changes.

So you just have to substract 5 hours to get the time in EST.

Dan Dumitru
Actually GMT isn't UTC with daylight saving. You'll find that UTC and GMT are the same. Currently the UK is on GMT+1 (British Summer Time).
ChrisBD
@Chris - Pff, this is getting confusing... I based what I said on the list of timezones in Windows 7, you can see one listed here, for example: http://riotingbits.com/2009/getting-the-current-time-in-a-different-time-zone-c-sharp/ - and in that list GMT is defined as UTC with daylight saving changes. Now, I don't know how consistent the timezone definitions are across different mediums...
Dan Dumitru
I just did a little code test with .NET 3.5, converting DateTime.UtcNow first to "Eastern Standard Time", then to "GMT Standard Time", and I did get a difference of 5 hours. But you're right, Chris, GMT is *normally* the same as UTC - it seems that Windows (at least Win 7) treats it differently.
Dan Dumitru
+1  A: 

The simplest way would probably be to just take 5 hours off the time like so.

DateTime dateTime = DateTime.UtcNow;
dateTime.AddHours(-5);

But this won't account for daylight savings etc. But you could always code for that possibility.

Dave
A: 
ChrisBD