It seems important to exactly match the ISO string format for TryParseExact to work. I think Exact is Exact, and this answer is obvious to most, but anyway ...
In my case, the Reb.Cabin answer does not work, since I have a slightly different input according to my "value" below.
Value: 2012-08-10T14:00:00.000Z
Within a few milliseconds there are a few more 000, and there may be more.
However, if I add .fff to the format as shown below, everything is fine.
Line format: @"yyyy-MM-dd\THH:mm:ss.fff\Z"
In VS2010 Immediate window:
DateTime.TryParseExact(value,@"yyyy-MM-dd\THH:mm:ss.fff\Z", CultureInfo.InvariantCulture,DateTimeStyles.AssumeUniversal, out d);
true
You may need to use DateTimeStyles.AssumeLocal , and also depending on which zone your time is for ...
Rob Von Nesselrode Aug 14 '12 at 7:15 2012-08-14 07:15
source share