Question in DateTime.ParseExact format

I have date and time strings that might look something like this:

"1 13 2009 2300", "1 14 2009 0", "1 14 2009 100"

what i need to parse DateTime.

I tried:

string[] sExpectedFormats = {"M d yyyy Hmm", "M d yyyy hmm", "M d yyyy 0"};
DateTime dtReportDateTime = DateTime.ParseExact(sReportDateTime, 
 sExpectedFormats, 
 System.Globalization.CultureInfo.InvariantCulture,
 System.Globalization.DateTimeStyles.None);

but he fails on the third "1 14 2009 100." I'm not sure which format to use for this?

To clarify, I get this data in the feed as part of the date "1 14" and the time part as "100", so I concatenate it so that I can parse the DateTime.

thanks

+3
source share
2 answers

, "100" "10", "0", H h "10", .

, , 4 3. , , :)

, , , "H" "h" - , , , .

, ,

{"M d yyyy HHmm", "M d yyyy 0"}
+6

, , "hmm" = "100" 1:00 PM. , "" "hmm tt" = "100 AM".

: . , .

0

Source: https://habr.com/ru/post/1723910/


All Articles