I am trying to convert
a string of the below format
dd/MM/yyyy hh:mm:ss.fff
into DateTime value
easiest way?
BTW
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime.ParseExact(timeString, "dd/MM/yyyy hh:mm:ss.fff",culture);
Throws an invalid time exception
Eg.
11/12/2009 13:30:00.000
Where 12 is the month (i know weird)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You have to use HH
string timeString = "11/12/2009 13:30:00.000";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime dateVal = DateTime.ParseExact(timeString, "dd/MM/yyyy HH:mm:ss.fff", culture);
Method 2
hh:mm:ss.fff should be HH:mm:ss.fff since you’re using 24-hour format.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0