Search code examples
javascriptdateiso8601

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


Here is a standard 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


Solution

  • Simple way:

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