要将 "10/03 00:11:17:265" 转换成 "2023/06/26 00:11:17",可以按照以下步骤:

  1. 使用 DateTime.ParseExact 方法将 "10/03 00:11:17:265" 转换成 DateTime 对象。
string input = "10/03 00:11:17:265";
DateTime date = DateTime.ParseExact(input, "MM/dd HH:mm:ss:fff", CultureInfo.InvariantCulture);
  1. 使用 DateTime 对象的 ToString 方法将其转换成指定格式的字符串。
string output = date.ToString("yyyy/MM/dd HH:mm:ss");

完整代码如下:

string input = "10/03 00:11:17:265";
DateTime date = DateTime.ParseExact(input, "MM/dd HH:mm:ss:fff", CultureInfo.InvariantCulture);
string output = date.ToString("yyyy/MM/dd HH:mm:ss");
Console.WriteLine(output); // 输出:2023/10/03 00:11:17
``
c# 怎么将1003 001117265 转换成 20230626 001117

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

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