I\'m having huge problems with solving this problem. I\'m trying to parse a string using Datetime.ParseExact().
I have the following code:
DateTime.P         
        Since H specifier can be 2 digit, this method try to parse your 83 with H specifier. Since there is no such an hour, you get FormatException.
For your case, one way to prevent this is putting a leading zero just before your 8.
var s = "20151210 832";
var result = s.Split(' ')[0] + " 0" + s.Split(' ')[1];
var dt = DateTime.ParseExact(result, "yyyyMMdd Hmm", CultureInfo.InvariantCulture);
Be aware, this will not work for all cases. For example, if your hour part already two digit, if your single minute does not have leading zero.. etc.
Or you can put delimiter for your all parts but in such a case, you need to manipulate both your string and format.
.NET Team suggest this way as well.
Just insert a separator before minutes (for example, a whitespace) and then you can parse it like this:
string example = "20151210 832";
example = example.Insert(example.Length - 2, " ");
var dateTime = DateTime.ParseExact(example, "yyyyMMdd H mm", CultureInfo.InvariantCulture);
I assume that the datetime string always contains two digits specifying minutes (check an article about Custom Date and Time Format Strings). If my assumption is wrong then this string cannot be parsed.