Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js returns GMT time and not local time for "new Date()". Is that a bug?

If not a bug, how to tell node my timezone? If bug, is this reported already?

like image 394
Jaseem Avatar asked Mar 31 '12 21:03

Jaseem


2 Answers

If it is a bug, it does not exist in my version of Node. It is true that the Node.js REPL prefers to announce in GMT in my version:

> new Date()
Sat, 31 Mar 2012 21:51:47 GMT

But it is in fact timezone-aware, that is just not what the REPL shows when stringifying it:

> new Date().getTimezoneOffset()
-120
> "" + new Date()
'Sat Mar 31 2012 23:51:56 GMT+0200 (CEST)'

(I am running Node.js v0.6.1 on Ubuntu.)

like image 59
CR Drost Avatar answered Sep 20 '22 04:09

CR Drost


This is not a bug, just a choice of how Node decides to represent a Date object in its REPL. Also, as of node v0.7.x, this output has been changed to display local time, matching the browser behavior:

☮ ~ (master) ⚡ node
> process.version
'v0.7.7'
> new Date
Sat Mar 31 2012 15:12:13 GMT-0700 (PDT)
like image 34
TooTallNate Avatar answered Sep 22 '22 04:09

TooTallNate