开发者

how to convert string "dd.MM.yyyy HH:mm:ss.mmm" to the datetime in c#

开发者 https://www.devze.com 2023-03-01 09:00 出处:网络
I try to convert string type \"dd.MM.yyyy HH:mm:ss.mmm\" to the datetime using the way below: DateTime result;

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

精彩评论

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