开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜