Possible Duplicate:
Parse DateTime with timezone of form PST/CEST/UTC/etc
I have a date string in the following format
Fri, 14 Dec 2012 6:52 am PST
I want to convert it to date time. I am using DateTime.TryParseExact to achieve it, but I am not able to read the time zone. If I change the string (without the time zone) to
Fri, 14 Dec 2012 6:52 am
and use
DateTime.TryParseExact(DateString, "ddd, dd MMM yyyy h:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None,out dt)
it works.
How can I read the time zone.
Edit – I am getting the data from the Yahoo weather API (e.g. http://weather.yahooapis.com/forecastrss?w=2420380).
Thanks.
I don’t believe there’s a custom date and time format specifier which handles time zones (as opposed to current UTC offsets). Even if there were, time zone abbreviations are potentially ambiguous, so they’re generally poor as a way of communicating time zone information. Unfortunately they’re widely used, of course…
I suspect you’ll be best off creating a map from abbreviation to “best guess time zone”, then stripping whatever’s after the last space from your input string, and using that to get the zone.
Just in case anyone was wondering, Noda Time doesn’t handle this yet either – but I’m hoping to make progress on it at some point 🙂