I'd like to use date time format string (possibly UTC) which is understandable and parsable on as many platforms and languages as possible? At least PHP, Python, Perl, Java, Rails and some common C++ library should be able to understand it.
我想使用可以在尽可能多的平台和语言上理解和解析的日期时间格式字符串(可能是UTC)?至少PHP,Python,Perl,Java,Rails和一些常见的C ++库应该能够理解它。
Which one should I use?
我应该使用哪一个?
Sample from MSDN:
来自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
4 个解决方案
#1
Stick with ISO8601 and you can't go wrong.
坚持使用ISO8601,你不会出错。
Preferably, YYYYMMDD HH:mm:ss [TZ] format as it is the most widely used.
优选地,YYYYMMDD HH:mm:ss [TZ]形式,因为它是最广泛使用的。
And definitely UTC "under the covers" if you are decoupling local time at the presentation layer of the application from internal stored time.
如果您将应用程序的表示层的本地时间与内部存储时间分离,那么UTC绝对是“在幕后”。
#3
ISO 8601 is the way to go. See this document for a useful introduction. You'll want to specify the time zone along with the date/time, I would suggest.
ISO 8601是要走的路。请参阅此文档以获得有用的介绍。我建议你要指定时区以及日期/时间。
#4
I'd go with ISO 8601 also, or simply the (unix_time ??) format which is number of seconds since 00:00 on 01/01/1970 - you can always parse it to get the desired time (even if it is a little more effort)
我也会使用ISO 8601,或者简单地使用(unix_time ??)格式,这是自1970年1月1日00:00以来的秒数 - 你总是可以解析它以获得所需的时间(即使它是一个多一点努力)
#1
Stick with ISO8601 and you can't go wrong.
坚持使用ISO8601,你不会出错。
Preferably, YYYYMMDD HH:mm:ss [TZ] format as it is the most widely used.
优选地,YYYYMMDD HH:mm:ss [TZ]形式,因为它是最广泛使用的。
And definitely UTC "under the covers" if you are decoupling local time at the presentation layer of the application from internal stored time.
如果您将应用程序的表示层的本地时间与内部存储时间分离,那么UTC绝对是“在幕后”。
#2
The round-trip formats are ISO 8601 compliant. I would use them.
往返格式符合ISO 8601标准。我会用它们。
#3
ISO 8601 is the way to go. See this document for a useful introduction. You'll want to specify the time zone along with the date/time, I would suggest.
ISO 8601是要走的路。请参阅此文档以获得有用的介绍。我建议你要指定时区以及日期/时间。
#4
I'd go with ISO 8601 also, or simply the (unix_time ??) format which is number of seconds since 00:00 on 01/01/1970 - you can always parse it to get the desired time (even if it is a little more effort)
我也会使用ISO 8601,或者简单地使用(unix_time ??)格式,这是自1970年1月1日00:00以来的秒数 - 你总是可以解析它以获得所需的时间(即使它是一个多一点努力)