23

For instance,

const d = new Date("2012-08-20T15:00:00-07:00");

d here is a UTC time with time offset = 07:00. Does it still require Z like this 2012-08-20T15:00:00-07:00Z? Is this correct?

If I take this string with Z and parse it using Date.parse() method in JavaScript, it throws an error. Not sure what is wrong!

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Cute_Ninja
  • 4,742
  • 4
  • 39
  • 63

2 Answers2

30

No, you should not include the "Z" with a time zone offset.

From rfc3339:

  Z           A suffix which, when applied to a time, denotes a UTC
              offset of 00:00; often spoken "Zulu" from the ICAO
              phonetic alphabet representation of the letter "Z".

The "Z" is a zero time offset, so including it with an explicit offset (especially a non-zero one) doesn't makes sense.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
14

Quoting W3C note on Date and Time Formats:

YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

where:

[...]

TZD  = time zone designator (Z or +hh:mm or -hh:mm)

Notice the or word above. You either specify time zone offset or Z for Zulu (no offset).

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • The Z actually stands for Zero. The word Zulu is just the NATO phonetic way to say "Z", not the other way around. – Ted Bigham May 07 '15 at 20:36
  • 3
    @TedBigham That is incorrect, Z does not stand for zero. Each time zone offset was assigned a letter from the alphabet: https://en.wikipedia.org/wiki/List_of_military_time_zones – smcs Feb 04 '16 at 23:56
  • @speedymcs The point is that Z doesn't stand for Zulu. It's just 'Z' which is the 00:00 time zone. Yes it's also called Zulu because of the 'Z', but not the other way around. If for some crazy reason the 'Z' time zone was named Pumpkin, it would still be a 'Z' here, not a 'P'. I guess "stands for" was not the right term. – Ted Bigham Feb 05 '16 at 00:23
  • 1
    @TedBigham You stated that Z stands for zero, my point was to correct that. I agree with the rest! – smcs Feb 05 '16 at 03:23