Date object not returning the correct locale time

353 views
Skip to first unread message

james33

unread,
Apr 9, 2012, 12:49:14 AM4/9/12
to nod...@googlegroups.com
I'm running node 0.6.14 on a Joyent machine (OS is a varient of Solaris). The timezone is set to US/Central, but the Date object in node doesn't seem to recognize this. Below are the outputs of a few different console.logs:

process.env.TZ: 'US/Central'

new Date(): 'Mon, 09 Apr 2012 04:45:28 GMT'

new Date().toLocaleString(): 'Mon Apr 09 2012 05:45:28 GMT+0100 (CST)'

The current US/Central time is actually 'Sun Apr 08 2012 23:45:28 GMT -0500 (CDT)'. Is this a bug or am I doing something wrong?

Matt Patenaude

unread,
Apr 9, 2012, 1:07:45 AM4/9/12
to nod...@googlegroups.com
Hmm, European CST is GMT+1, it could be using that instead (in spite of the US/ bit there). Try changing to (for example) 'America/Chicago' and see if you get different results?

-Matt


--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

james33

unread,
Apr 9, 2012, 1:56:38 PM4/9/12
to nod...@googlegroups.com
I still get the same result.

Matt Patenaude

unread,
Apr 9, 2012, 2:08:03 PM4/9/12
to nod...@googlegroups.com, nod...@googlegroups.com
And what if you pick a completely different timezone, e.g., America/Los_Angeles?

-Matt

Sent from my iPhone

james33

unread,
Apr 9, 2012, 2:32:58 PM4/9/12
to nod...@googlegroups.com
I get GMT+0100 (PST) with that.

Matt Patenaude

unread,
Apr 9, 2012, 5:58:37 PM4/9/12
to nod...@googlegroups.com
Just to make sure environmental variables aren't getting messed with somehow, try running this:

echo "console.log((new Date()).toLocaleString());" | TZ='America/Los_Angeles' node

Should print out a locale string at GMT-0700 (PDT). If it doesn't, then I'd defer to someone else who's more knowledgeable about the internals of Node's Date object than myself. :)

-Matt

james33

unread,
Apr 9, 2012, 6:02:02 PM4/9/12
to nod...@googlegroups.com
It returns Mon Apr 09 2012 23:01:04 GMT+0100 (PST)

Ben Noordhuis

unread,
Apr 9, 2012, 7:34:33 PM4/9/12
to nod...@googlegroups.com
On Tue, Apr 10, 2012 at 00:02, james33 <jam...@gmail.com> wrote:
> It returns Mon Apr 09 2012 23:01:04 GMT+0100 (PST)

You should report this to V8 because I'm 99% sure it's a bug. To wit,
this is the V8 shell on a Linux or OS X system:

$ TZ='America/Los_Angeles' out/ia32.release/shell -e 'print(new
Date().getTimezoneOffset())'
420
$ TZ='Europe/Amsterdam' out/ia32.release/shell -e 'print(new
Date().getTimezoneOffset())'
-120

And this is on a Solaris system:

$ TZ='America/Los_Angeles' out/ia32.release/shell -e 'print(new
Date().getTimezoneOffset())'
-60
$ TZ='Europe/Amsterdam' out/ia32.release/shell -e 'print(new
Date().getTimezoneOffset())'
-60

If I have some time to kill, I'll look into fixing it myself.

james33

unread,
Apr 9, 2012, 10:41:11 PM4/9/12
to nod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages