Reputation: 3082
I am trying to parse a string using ParseExact()
method:
DateTime.ParseExact(@"UTC 2014-07-08 13:11:40.396", @"UTC yyyy-MM-dd HH:mm:ss.FFF",null);
This gives following error message:
DateTime.ParseExact(@"UTC 2014-07-08 13:11:40.396", @"UTC yyyy-MM-dd HH:mm:ss.FFF",null) threw an exception of type 'System.FormatException' base: {"String was not recognized as a valid DateTime."}
Upvotes: 2
Views: 1287
Reputation: 93621
Try CultureInfo.InvariantCulture
. That will force it to ignore the current culture settings (and is generally what I have had to use in production to avoid these problems)
DateTime.ParseExact(@"UTC 2014-07-08 13:11:40.396", @"UTC yyyy-MM-dd HH:mm:ss.FFF",CultureInfo.InvariantCulture);
Unlike culture-sensitive data, which is subject to change by user customization or by updates to the .NET Framework or the operating system, invariant culture data is stable over time and across installed cultures and cannot be customized by users. This makes the invariant culture particularly useful for operations that require culture-independent results, such as formatting and parsing operations that persist formatted data, or sorting and ordering operations that require that data be displayed in a fixed order regardless of culture.
Upvotes: 7