可以使用 DateTime.ParseExact 方法将字符串解析为 DateTime 类型,再使用 ToString 方法将其转换为指定格式的字符串。

以下是示例代码:

string input = '10/03 06:21:21:328';
DateTime datetime = DateTime.ParseExact(input, 'MM/dd HH:mm:ss:fff', null);
string output = datetime.ToString('yyyy/MM/dd HH:mm:ss');
Console.WriteLine(output);  // 输出:2023/10/03 06:21:21
C# 将时间字符串 10/03 06:21:21:328 转换为 2023/10/03 06:21:21 格式

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

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