要将DateTime对象从"2023-06-28 23:57:00"转换为"2023-06-28",可以使用DateTime的ToString方法和指定的日期格式。

以下是一个示例代码:

DateTime dateTime = DateTime.Parse("2023-06-28 23:57:00");
string dateString = dateTime.ToString("yyyy-MM-dd");

Console.WriteLine(dateString);

输出结果为:"2023-06-28"。

在代码中,首先使用DateTime.Parse方法将字符串"2023-06-28 23:57:00"转换为DateTime对象。然后,使用DateTime对象的ToString方法并指定日期格式"yyyy-MM-dd"将DateTime对象转换为字符串。最后,将转换后的字符串输出到控制台。

c# 将datetime 2023-06-28 235700 转换成 datetime 2023-06-28

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

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