我的 Windows 日期格式是月/日/年。如果我想设置格式为“yyyy/MM/dd HH:mm:ss”的 StartTime,我该怎么做。我尝试以下代码。
DateTime StartTime = DateTime.ParseExact("2011/01/04 09:30:00", "yyyy/MM/dd HH:mm:ss", null);
但 StartTime 会在 1/4/2011 9:30:00 AM 出现。 (月/日/年 hh:mm:ss)
最佳答案
您正在正确解析时间,但以默认格式显示。试试 StartTime.ToString("yyyy/MM/dd HH:mm:ss")
关于c# - 如何转换时间格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4595360/