Converting a String to DateTime

后端 未结 17 2859
南方客
南方客 2020-11-21 06:12

How do you convert a string such as 2009-05-08 14:40:52,531 into a DateTime?

17条回答
  •  执笔经年
    2020-11-21 06:53

    Since you are handling 24-hour based time and you have a comma separating the seconds fraction, I recommend that you specify a custom format:

    DateTime myDate = DateTime.ParseExact("2009-05-08 14:40:52,531", "yyyy-MM-dd HH:mm:ss,fff",
                                           System.Globalization.CultureInfo.InvariantCulture);
    

提交回复
热议问题