将字符串转换为DateTime [英] Converting a String to DateTime

查看:124
本文介绍了将字符串转换为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何转换一个字符串,如 2009-05-08 14:40:​​52531 的DateTime

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

推荐答案

由于要处理24小时基于时间和你有一个逗号分隔秒部分,我建议您指定自定义格式为:

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)

这篇关于将字符串转换为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆