jbyrd
jbyrd

Reputation: 5585

Difference between ISO formatting "+00:00" and "Z"?

What's the difference between this date format:

"2021-01-01T00:00:00.000Z"

and this one:

"2021-01-01T00:00:00+00:00"

Are they both valid ISO formats? When I call new Date().toISOString() in JavaScript, I get the first one.

For some reason, I'm having trouble finding a definitive answer on this.

Upvotes: 10

Views: 6351

Answers (2)

RobG
RobG

Reputation: 147413

ECMA-262 defines a "string interchange format" that is generated by toISOString and must also be parsed by the built–in parser. It states:

Z is the UTC offset representation specified as "Z" (for UTC with no offset) or an offset of either "+" or "-" followed by a time expression HH:mm (indicating local time ahead of or behind UTC, respectively)

So while toISOString produces "Z", the parser will also accept "+00:00" and "-00:00". Correct parsing of any other format is implementation dependent (and hence unreliable).

Upvotes: 0

Quentin
Quentin

Reputation: 943615

From Wikipedia:

An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00".

Upvotes: 6

Related Questions