Context
我想从PHP8.2中的DateTime
对象生成ISO-8601字符串.Date
类的date_f或mat()
函数有two related predefined constants:
-
DATE_ISO8601
-"Y-m-d\\TH:i:sO"
注意:此格式与ISO-8601不兼容,但出于向后兼容的原因而保留此格式.改用DateTimeInterface::ISO8601_Expanded,DateTimeInterface::Atom与ISO-8601兼容.(参考ISO8601:2004第4.3.3节d条) -
DATE_ISO8601_EXPANDED
-"X-m-d\\TH:i:sP"
通过始终包含符号字符,此格式允许年份范围超出ISO-8601的正常范围0000-9999.它还说明了时区部分(+01:00)与ISO-8601兼容.
Question
DATE_ISO8601_EXPANDED
格式在字符串中添加一个前导+
字符,其他语言(特别是SWIFT)的ISO8601解析器无法识别该字符:
+2023-03-29T05:54:21+00:00
DATE_ISO8601
的输出为:
2023-03-29T05:54:21+0000
我无法确定关于DATE_ISO8601
的警告是什么意思.这是否意味着:
- "This f或mat doesn't adhere to the latest revision of ISO8601, so you should use the 'expanded' variant instead."
或
- "There are bugs in this f或mat that sometimes produce invalid ISO8601 output, so you should use the expanded f或mat."
Hilariously, section 4 of ISO 8601 is not publicly available without purchase, so I can't read it. But the "expanded" f或mat doesn't appear to be standard ISO8601 either, since the spec calls f或 a leading +
symbol only when the year is greater than 9999.