Converting a String to DateTime

后端 未结 17 2844
南方客
南方客 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:55

    try this

    DateTime myDate = DateTime.Parse(dateString);
    

    a better way would be this:

    DateTime myDate;
    if (!DateTime.TryParse(dateString, out myDate))
    {
        // handle parse failure
    }
    

提交回复
热议问题