Why does this method use UTC timezone (Z
) and not include the local time offset (+/-HH:SS
) instead? The "ISO" in the method name refers to ISO 8601—which allows for "time zone designations" to be expressed as part of its format.
In other words, new Date()
tells me both the date and time, and the timezone offset (via getTimezoneOffset()
). But toISOString()
only tells me the date and time in one timezone—it discards the information of what time it was in the locale that the new Date()
originated.
Wouldn't it make sense for toISOString()
to also include the originating timezone's offset from UTC? toISOString()
's omission of +/-HH:SS loses information about the originating Date
if it's used for serializing.
All my AJAX calls (Angular, jQuery) serialize via toISOString()
, thus losing the local time of the serialized date when it's communicated to the server. Any way to get a JavaScript Date
to output an ISO-formatted string that also includes offset (besides using a library like Moment.js), or do I need to write my own method?