13

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)

soldieraman
  • 2,600
  • 7
  • 38
  • 52

2 Answers2

17

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);
Adriaan Stander
  • 156,697
  • 29
  • 278
  • 282
4

hh:mm:ss.fff should be HH:mm:ss.fff since you're using 24-hour format.

Anton Gogolev
  • 110,157
  • 37
  • 194
  • 282