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?

Rob
  • 45,296
  • 24
  • 122
  • 150
Wondering
  • 4,950
  • 22
  • 71
  • 90

2 Answers2

4

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("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 Eastern Standard Time, which is the id associated with "Eastern Time (US & Canada)", but you can get a full list of the time zones available by running the following code:

foreach(TimeZoneInfo info in TimeZoneInfo.GetSystemTimeZones())
{
    Console.WriteLine("Id: {0}", info.Id);
    Console.WriteLine("   DisplayName: {0}", info.DisplayName);
}
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Rob
  • 45,296
  • 24
  • 122
  • 150
1
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

Lasse Espeholt
  • 17,622
  • 5
  • 63
  • 99