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,630
  • 7
  • 39
  • 52

2 Answers2

18

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
  • 162,879
  • 31
  • 289
  • 284
4

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

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288