首页 > 解决方案 > Javascript toISOString() 不同格式

问题描述

根据Mozilla和我引用

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix "Z".

I always see YYYY-MM-DDTHH:mm:ss.sssZ format when I invoke method like

new Date().toISOString()

So in which case

new Date().toISOString() 

will return format like

YYYYYY-MM-DDTHH:mm:ss.sssZ ?

Can anyone please give it with example?

标签: javascriptdate

解决方案


它是扩展的年份表示,额外的字符是因为它以 a 开头+-表示 AD/BC。

来源:ISO_8601 第 4.5.1 节(第 13 页)。维基百科上提供了一个总结版本。


推荐阅读