I rarely parse xml files and when I try to use the features integrated in Linq2Xml. However today I stumbled upon a date format I am not able to cast via:
XElement element = ...
var date = (DateTime)element;
The date is in the following format:
01/28/2009 02:31:54 CET
I already tried to parse the date using TryParse in various combinations, cultures, but whatever format I try the datetime parser complains about the space at position 20. Is there a way to parse this date without splitting the string or doing awkward things?
It sounds like the timezone abbreviations (e.g. CET) aren’t recognized. Do you know the offset?
This person is having a related problem:
Parse DateTime with time zone of form PST/CEST/UTC/etc
An example from his post:
Obviously your date time format is a bit different, but it’s an idea to bail you out.
If you can, ask the person giving you the XML to generate the date/times with ISO 8601 format to avoid custom parsing.