在 C# 中,可以使用 DateTime.ParseExact 方法将字符串转换为 DateTime 对象。需要提供日期时间的格式字符串作为参数。

以下是将字符串 '20230823 101456' 转换为 DateTime 对象的示例代码:

string dateTimeString = '20230823 101456';
string format = 'yyyyMMdd HHmmss';

DateTime dateTime = DateTime.ParseExact(dateTimeString, format, System.Globalization.CultureInfo.InvariantCulture);

Console.WriteLine(dateTime);

输出结果为:2023/08/23 10:14:56

C# 字符串转 DateTime:将 '20230823 101456' 转换为日期时间

原文地址: https://www.cveoy.top/t/topic/qsso 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录