I am currently trying to parse a string that is obtained from an xml that is downloaded from the web every few minutes. The string looks like this:
Thu Jul 12 08:39:56 GMT+0100 2012
At first I just did a string.split and took out everything after the time (GMT+0100 2012) and inserted 2012 after the date.
This worked great until the date changed to:
Thu Jul 12 08:39:56 GMT+0000 2012
So I would like to dynamically pasre the GMT+ whatever as they send me that string in c#.
Any advice would be appreciated.
You can use
DateTime.ParseExactwith a custom date and time format string:This will throw a format exception if the string and format string do not match exactly, so you may want to use
DateTime.TryParseExactthat will return afalseif it fails.Instead of
DateTimeyou may want to useDateTimeOffsetthat preserved timezone information , as @Keith commented – this may be important to your application.