You’ll notice that if you use the browser’s dev tools console and type in
new Date() you’ll get the current date printed in a nice human readable string which should be the current time in your location.
-> new Date() <- Mon Apr 01 2019 23:33:08 GMT-0500 (Central Daylight Time)
But what happens when you try to do the same thing in Node?
You’d expect the same output, but thats not what you get.
node > new Date() 2019-04-02T04:53:45.909Z
Why does it look like this? Its because when you output a Date object in the browser, the browser will by default use
Date.toString() which will give it that nice, human readable look.
In Node however, Dates are by default outputted with
Date.toISOString() which returns a hard to read notated form of the current date without any timezone offset (UTC+0).
To get around this you can simply manually call
Then when you run it, you will see the current date formatted nicely with your current timezone offset.
> new Date().toString() 'Mon Apr 01 2019 23:55:26 GMT-0500 (CDT)'
And then do