<分区>
将字符串转换为日期和时间的最佳方法是什么:
"Jan 7 09:27:56"
也可以这样:"Jan 12 09:27:56"
<分区>
将字符串转换为日期和时间的最佳方法是什么:
"Jan 7 09:27:56"
也可以这样:"Jan 12 09:27:56"
最佳答案
您可以使用 MMM d HH:mm:ss
作为 custom date and time format strings使用基于英语 并使用:
作为TimeSeparator
文化喜欢InvariantCulture
.
var s = "Jan 7 09:27:56";
DateTime dt = DateTime.ParseExact(s, "MMM d HH:mm:ss", CultureInfo.InvariantCulture);
或
var s = "Jan 12 09:27:56";
DateTime dt = DateTime.ParseExact(s, "MMM d HH:mm:ss", CultureInfo.InvariantCulture);
关于c# - 如何将日期时间格式转换为日期和时间对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975621/