0

I'm trying to parse a date time string which contains some timezone information (May 1st 2014 9:45pm in EST timezone):

DateTime RecordedDateTime;
string fixedRecordedDateTime = "Thu May 01 21:45:00 +0500 2014";
string[] dateFormats = { "ddd MMM dd HH:mm:ss zzz yyyy" , "ddd MMM dd HH:mm:ss K yyyy" };
DateTime.TryParseExact(fixedRecordedDateTime, dateFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out RecordedDateTime);

The DateTime object gets 5/1/2014 12:45 PM Local time (I'm in EST)

if I use (May 1st 2014 9:45pm in PST timezone):

string fixedRecordedDateTime = "Thu May 01 21:45:00 +0800 2014";

The DateTime object gets 5/1/2014 09:45 AM Local time

I don't understand what's going wrong, why am I not able to correct local time after giving the timezone information information.

I'm trying to use DateTime instead of DateTimeOffset, is there anyway to get this parsed correctly?

rboy
  • 2,018
  • 1
  • 23
  • 35

1 Answers1

3

string fixedRecordedDateTime = "Thu May 01 21:45:00 +0500 2014";

This is 21:45 in UTC+0500. That would be 16:45 in UTC, or 12:45 in EDT (UTC-0400). I think you got your + and - reversed in the offset.

pmcoltrane
  • 3,052
  • 1
  • 24
  • 30
  • Thanks, I guess this post also needs to be corrected, I converted EST PST etc to a number using the code on the page. – rboy May 09 '14 at 18:39
  • http://stackoverflow.com/questions/13881819/c-sharp-tryparseexact-reading-time-zone – rboy May 09 '14 at 18:40