c# - 如何将日期时间格式转换为日期和时间对象?

标签 c# datetime

<分区>

将字符串转换为日期和时间的最佳方法是什么:

"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/

相关文章:

c# - 在 datetime 变量中获取 24 小时时间格式

c# - 如何在 C# 中将 DateTimeOffset 添加到 DateTime?

c# - BIDS 和 VS 中的 SSIS 自定义控件任务调试 UI

c# - 从正在等待的事件返回反馈

ios - SQLite Datetime 24小时前查询

java - 转换 UTC 时间 HH :mm:ss to Device time HH:mm:ss and adding Day saving time if available

postgresql - 仅选择今天(从午夜开始)的时间戳

C# 正则表达式既不包含这个也不包含那个

c# - 如何将字符串分成字符

c# - Visual Studio - 以编程方式配置源代码控制解决方案