bessarabov bessarabov - 16 days ago 4
Javascript Question

How to output date in javascript in ISO 8601 without milliseconds and with Z

Here is a standart way to serialise date as ISO 8601 string in JavaScript:

var now = new Date();
console.log( now.toISOString() );
// outputs '2015-12-02T21:45:22.279Z'


I need just the same output, but without milliseconds. How can I output
2015-12-02T21:45:22Z
?

Answer

Simple way:

console.log( now.toISOString().split('.')[0]+"Z" );