我遇到了 C# 的奇怪行为。是这样的..
var date = DateTime.Now.ToString("MM/dd/yyyy");
我期待的是
04/24/2009
但实际上它返回了
04-24-2009
我的操作系统文化是 en-GB,我使用的是 .Net 3.5 和 WPF
请问有什么解决办法... ???
最佳答案
根据自定义日期和时间格式字符串的 MSDN 文档,/
是一个占位符:
Represents the date separator defined in the current DateTimeFormatInfo.DateSeparator property. This separator is used to differentiate years, months, and days.
如果你想要一个明确的斜线,使用“MM'/'dd'/'yyyy”:
DateTime.Now.ToString("MM'/'dd'/'yyyy")
关于c# - C# 中的日期时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/785795/