views:

47

answers:

2

I have a date format, something similar to:

Mon, 11 Aug 2009 13:15:10 GMT

How do I convert this to EST format?

+1  A: 
var datetime = DateTime.Parse("Sat, 21 Aug 2010 13:15:10 GMT");
TimeZoneInfo estZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime estTime = TimeZoneInfo.ConvertTime(datetime, estZone);

EST can mean different times, which do you want: http://en.wikipedia.org/wiki/EST

lasseespeholt
+1  A: 

This, or similar should do the trick:

var dateString = "Tue, 11 Aug 2009 13:15:10 GMT";
var date = Convert.ToDateTime(dateString);
var result = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time"));

It's worth mentioning, that your originally specified Mon, 11 Aug 2009, is actually incorrect, hence I've changed it to Tue, 11 Aug 2009 so the code will run, as the Convert.ToDateTime throws an exception if the day does not match the date.

I've also assumed that you mean US Eastern Standard Time, but you can get a full list of the TimeZone's available by running the following code:

foreach(TimeZoneInfo info in TimeZoneInfo.GetSystemTimeZones())
{
    Console.WriteLine("Id: {0}", info.Id);
    Console.WriteLine("   DisplayName: {0}", info.DisplayName);
}
Rob