views:

687

answers:

2

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)

+1  A: 

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);
astander
Sometimes you just need another eye to look at your code. Thanks for that. Very silly of me.
soldieraman
+1  A: 

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

Anton Gogolev