【发布时间】:2016-05-11 21:30:35
【问题描述】:
C# System.DateTime.Now 给我 date with time ,但它给我格式化我在 windows calander 中设置的任何内容,即 (a.m.)(p.m.) 甚至 (xyz),如何获得标准时间格式 (AM/PM ) 无论在 windows calander 中设置的自定义时间格式如何?
【问题讨论】:
-
DateTime 就是这样,它没有专门的“格式” - 如果你希望它以某种格式显示,你正在用它做一些事情......
-
日期的表示方式与其值无关。
-
如果您需要标准格式,请为
DateTime对象创建一个扩展方法,该方法使用 ToString() 方法并提供您自己的格式。 This link 显示用于格式化的字符。 -
@To_ALLtry to change windows time AM/PM format to custom values like xyz, then check with System.DateTime.Now... 它会给你 mm/dd/yyyy hh:mm:ss xyz ——
标签: c# datetime datetime-format