When I do new Date() in JS I get:
Thu Jul 26 2018 08:09:57 GMT+0200 (Central European Summer Time)
How can I get it in this format along with the included Z at the end?
2016-05-26t16:53:22.313Z
When I do new Date() in JS I get:
Thu Jul 26 2018 08:09:57 GMT+0200 (Central European Summer Time)
How can I get it in this format along with the included Z at the end?
2016-05-26t16:53:22.313Z
Though there are other answers available, I recently found that you can call toJSON()
on the date object to get the ISO formatted string:
console.log((new Date()).toJSON());
You can use toISOString
to get this:
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".
console.log(new Date().toISOString());