Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 343
Cute_Ninja Avatar asked Feb 05 '13 18:02

Cute_Ninja


People also ask

What is the format for UTC date?

The UTC Time Format In other formats, UTC is replaced with Z, which is the zero UTC offset. For instance, UTC time in ISO-8601 is xx:xx:xxZ. The Z letter is added without a space. Another UTC format is a 12-hour clock time (AM/PM) xx:xx:xx.

What is Z in UTC format?

The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).

What is Z in datetime in C#?

Local date and time values is an offset from UTC (for example, +01:00, -07:00). All DateTimeOffset values are also represented in this format. The time zone component of DateTimeKind. Utc date and time values uses "Z" (which stands for zero offset) to represent UTC.

Is JavaScript date always UTC?

UTC() is a static method of the Date object. The syntax is always Date. UTC().


2 Answers

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.

like image 66
Laurence Gonsalves Avatar answered Oct 20 '22 03:10

Laurence Gonsalves


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

like image 40
Tomasz Nurkiewicz Avatar answered Oct 20 '22 04:10

Tomasz Nurkiewicz