I’m kind of stuck in a problem when I can’t parse the date and time from a string that I am reading from a text file. The string I get has the following format:
05SEP1998 2400
and I'm trying to parse a string through the following code:
string dateTimeStr = "05SEP1998 2400"
var provider = CultureInfo.InvariantCulture;
const string Format = "ddMMMyyyy hhmm";
var dateTime = DateTime.ParseExact(dateTimeStr, Format, provider);
But when parsing, the above code throws a FormatException:
String was not recognized as a valid DateTime.
Can someone help me solve this problem?
source
share