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.
Date.prototype.toISOString() The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .
The date. toISOString() method is used to convert the given date object's contents into a string in ISO format (ISO 8601) i.e, in the form of (YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss.
Time zones in ISO 8601 are represented as local time (with the location unspecified), as UTC, or as an offset from UTC.
If the DATEPARSE function is not available for the data that you're working with, or the field you are trying to convert is a number data type, you can use the DATE function instead. The DATE function converts a number, string or date expression to a date type.
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.
This seems like an error with Date.js. Using new Date('2012-08-27T14:57:00Z')
returns the correct date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With