JavaScript UTC date string


How to generate a UTC date string in JavaScript and Node.js.

Node.js

Enter the node REPL:

node

Generate new Date:

new Date();

Or call toISOString:

new Date().toISOString();

See example:

node
Welcome to Node.js v16.1.0.
Type ".help" for more information.
> new Date()
2021-04-28T20:49:52.578Z
> new Date().toISOString()
'2021-04-28T20:49:54.488Z'

Browser

Open browser Console via Developer Tools and run:

new Date().toISOString();

The date string will be formatted like:

YYYY-MM-DDTHH:mm:ss.sssZ


Please support this site and join our Discord!