c# - 哪种日期和时间格式与其他平台最兼容?

标签 c# .net datetime

我想使用在尽可能多的平台和语言上可以理解和解析的日期时间格式字符串(可能是 UTC)?至少PHP、Python、Perl、Java、Rails和一些常用的C++库应该能看懂。

我应该使用哪一个?

来自 MSDN 的示例:

Culture:                      English (United States)

(d) Short date: . . . . . . . 4/17/2006
(D) Long date:. . . . . . . . Monday, April 17, 2006
(t) Short time: . . . . . . . 2:29 PM
(T) Long time:. . . . . . . . 2:29:09 PM
(f) Full date/short time: . . Monday, April 17, 2006 2:29 PM
(F) Full date/long time:. . . Monday, April 17, 2006 2:29:09 PM
(g) General date/short time:. 4/17/2006 2:29 PM
(G) General date/long time (default):
    . . . . . . . . . . . . . 4/17/2006 2:29:09 PM
(M) Month:. . . . . . . . . . April 17
(R) RFC1123:. . . . . . . . . Mon, 17 Apr 2006 21:29:09 GMT
(s) Sortable: . . . . . . . . 2006-04-17T14:29:09
(u) Universal sortable (invariant):
    . . . . . . . . . . . . . 2006-04-17 21:29:09Z
(U) Universal full date/time: Monday, April 17, 2006 9:29:09 PM
(Y) Year: . . . . . . . . . . April, 2006
(o) Roundtrip (local):. . . . 2006-04-17T14:29:09.3011250-07:00
(o) Roundtrip (UTC):. . . . . 2006-04-17T21:29:09.3011250Z
(o) Roundtrip (Unspecified):. 2000-03-20T13:02:03.0000000

最佳答案

坚持使用 ISO8601 就不会出错。

最好是 YYYYMMDD HH:mm:ss [TZ] 格式,因为它使用最广泛。

如果您在应用程序的表示层将本地时间与内部存储时间分离,那么肯定是 UTC“在幕后”。

关于c# - 哪种日期和时间格式与其他平台最兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092075/

相关文章:

c# - 设置可为 null 的日期时间的属性值

c# - 如何重新映射程序集版本

c# - 如何在 Windows 窗体 C# 中为文本框设置 Scintilla

c# - SlimDX Device.Reset 崩溃并出现 "D3DERR_INVALIDCALL: Invalid call (-2005530516)"错误

c# - 如何为 IsChecked 属性设置动画?

python - 跨列计算数据框中的 null/NaN 值

c# - 为什么我收到 'an unhandled exception of type system executionengineexception occurred in system data dll' 错误?

c# - 在 switch 语句案例中使用属性?

c# - .NET WinForms - 如何监听系统注销、用户锁定、休眠启动和系统恢复的事件?

c - strptime 返回意外结果