Search code examples
javascriptparsingdateutc

Does UTC date string require the format specifier "Z" even if that string includes time offset?


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!


Solution

  • 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.