Reputation: 1037
-Current default time zone: 'US/Pacific-New'
-Local time and UTC all look good.
-$date
gives PDT just fine.
but new Date
in Node still gives UTC time?
new Date().getTimezoneOffset()
correctly gives 420
though
I thought Node used local time for new Date
operations just like the browsers, but I keep getting 2016-10-20T05:07:45.341Z
which is UTC time?
(node ver 6.7.0)
Upvotes: 0
Views: 37
Reputation: 241593
The Date
object stores time in milliseconds since the Unix epoch (without leap seconds). This is the value you see when you call .getTime()
or .valueOf()
. That is a purely UTC-based value, without any time zone.
Any string representation is the result of calls to toString
, toISOString
, etc. or implicit string conversion that occurs when logging to the debug console.
The implementations of the console debug output can vary across environments. Some will show a string in local time (Chrome, IE, Edge), and some will show a string in UTC (Node, FF).
If you want to see the local date/time in Node/FF without any libraries, call new Date().toString()
. The output will be in local time.
Upvotes: 1