Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top