C# 字符串日期时间格式转换 - 将 "2023-06-28 23:57:00" 转换为 "2023-06-28"
在C#中,可以使用DateTime.ParseExact方法将字符串转换为DateTime对象,并指定所需的格式。在这种情况下,格式为"yyyy-MM-dd"。以下是示例代码:\n\ncsharp\nstring input = "2023-06-28 23:57:00";\nDateTime dateTime = DateTime.ParseExact(input, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);\nstring result = dateTime.ToString("yyyy-MM-dd");\n\nConsole.WriteLine(result);\n\n\n输出结果为:\n\n\n2023-06-28\n
原文地址: https://www.cveoy.top/t/topic/pHXU 著作权归作者所有。请勿转载和采集!