SCO*_*SCO 36 standards iso date datetime-format
我想知道以下日期是否符合ISO8601标准:
2012-03-02 14:57:05.456+0500
Run Code Online (Sandbox Code Playgroud)
(当然,2012-03-02T14:57:05.456 + 0500是合规的,但没有那么多人类可读!)IOW,日期和时间之间的T是强制性的吗?
Kei*_*son 31
除非"信息交换中的合作伙伴"同意省略它,否则这是必需的.
引用ISO 8601标准,第4.3.2节:
字符[T]应用作时间指示符,以指示这些表达式中时间组件的表示的开始.[...]
注:通过信息交换中的合作伙伴的共同协议,在没有将日期和时间表示与本国际标准中定义的其他表示混淆的风险的应用中,可以省略字符[T].
省略它是相当普遍的,但如果表示是机器可读的并且您没有明确的协议可以省略它,则建议将其保留.
更新:Mark Amery的评论提出了一个很好的观点,即省略[T]的许可并不一定意味着允许用空格替换它.所以这:
2012-03-02T14:57:05.456+0500
Run Code Online (Sandbox Code Playgroud)
显然是合规的,这个:
2012-03-0214:57:05.456+0500
Run Code Online (Sandbox Code Playgroud)
如果合作伙伴同意省略[T],则允许,但是:
2012-03-02 14:57:05.456+0500
Run Code Online (Sandbox Code Playgroud)
显然不是(尽管它比[T]简单省略的版本更具可读性).
就个人而言,如果要求符合ISO 8601标准,我会包括[T],如果不是,那么我会使用空格(如果它将成为文件名的一部分,则使用连字符).我的猜测,并不仅如此,意图是让'T'被一个空格所取代,但标准并没有这么说.
另请参阅Charles Burns的答案中提到的RFC 3339第5.6节.
Cha*_*rns 13
这个日期是不是ISO-8601标准的基思·汤普森表示,但它是符合RFC 3339,ISO 8601排序的轮廓.请参阅RFC 3339中以下文本底部的注意:
date-time = full-date "T" full-time
NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
syntax may alternatively be lower case "t" or "z" respectively.
This date/time format may be used in some environments or contexts
that distinguish between the upper- and lower-case letters 'A'-'Z'
and 'a'-'z' (e.g. XML). Specifications that use this format in
such environments MAY further limit the date/time syntax so that
the letters 'T' and 'Z' used in the date/time syntax must always
be upper case. Applications that generate this format SHOULD use
upper case letters.
NOTE: ISO 8601 defines date and time separated by "T".
Applications using this syntax may choose, for the sake of
readability, to specify a full-date and full-time separated by
(say) a space character.
Run Code Online (Sandbox Code Playgroud)