Search code examples
javascriptdatejs

Date.js parsing an ISO 8601 UTC date incorrectly


Using the javascript library Date.js I am finding that when i pass into the Date.parse() function an ISO 8601 formatted UTC 0 date I am getting an object that is representative of the same date but with the local time zone added.

For example,

Given the date: 2012-08-27T14:57:00Z (in ISO 8601 format), which is showing a time of 14:57 UTC, why would this be parsed as 14:57 GMT-400 as opposed to 10:57 GMT-400?

I have created a fiddle to show it in action.

Please let me know if there is in fact an error or if my understanding of the parsing result is incorrect.


Solution

  • Yep, it's a bug - even a reported one.

    Might I recommend using Moment.js library instead? For example, this:

    console.log(moment('2012-08-27T14:57:00Z').toString());

    ... will correctly recognize that UTC time is given.