how to convert string "dd.MM.yyyy HH:mm:ss.mmm" to the datetime in c#
I try to convert string type "dd.MM.yyyy HH:mm:ss.mmm" to the datetime using the way below:
DateTime result;
string c;
tarihSaat[n 开发者_Python百科- 4] = DateTime.ParseExact(c, "dd.MM.yyyy HH:mm:ss.mmm", CultureInfo.InvariantCulture);
But I got FormatException error. How can I convert it? Thanks..
This should do it, you can't reuse a format string pattern twice ("m" in your sample), also you want to use "fff" for milliseconds. For details on custom date and time format strings check MSDN.
string c = "15.04.2011 14:32:15.444";
DateTime result = DateTime.ParseExact(c, "dd.MM.yyyy HH:mm:ss.fff",
CultureInfo.InvariantCulture);
精彩评论