Reputation: 21657
I'm working on parsing few XML files where I have datetime values saved as text. I'm not able to find what format is the below one -
20110123T233356,00-05
I tried both DateTime.Parse
and DateTimeOffset.Parse
and both of them failed. I also tried to identify the string in few places like here and here with no luck.
Upvotes: 2
Views: 189
Reputation: 109792
Assuming that the ",00" is hundredths of seconds and the "-05" is the timezone, you can parse it like this:
string dateStr = "20110123T233356,00-05";
string format = @"yyyyMMdd\THHmmss\,ffzz";
DateTime result;
if (DateTime.TryParseExact(dateStr, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
Console.WriteLine(result);
}
else
{
Console.WriteLine("Can't parse the date: " + dateStr);
}
However, that's a big assumption.
Note that you can also specify the format string without escaping the T
or the ,
as follows (but I escaped them to make it more obvious that they aren't format characters):
string format = "yyyyMMddTHHmmss,ffzz";
Upvotes: 8