我想将字符串5/4/2017 2:15:50 PM转换为日期时间。我用了
statustime="5/4/2017 2:15:50 PM"
statustimefrm=DateTime.Parse(statustime, Globalization.CultureInfo.CurrentCulture)
并且有效,但是我宁愿使用ParseExact。我用了
statustimefrm=DateTime.Parse(statustime, "M/d/yyyy HH:mm:ss tt",Globalization.CultureInfo.CurrentCulture)
但这给了我格式错误。有人知道使用的格式吗?
最佳答案
这对我有用
DateTime.ParseExact(timespan, "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);