Date with different timezone

1,931 views
Skip to first unread message

PV Sundarram

unread,
Jul 28, 2011, 9:37:53 PM7/28/11
to nod...@googlegroups.com
Hi,

I am new to node.js and found to my surprise, it doesnt have a strong and environment agnostic way of handling dates. 

Given that V8 is being used and node.js is trying to be conformant to how the browser behaves, but why doesnt it make it easy for me out of the box to handle dates with different timezones easily. 

I tried it with REPL, 
> new Date().getTimezoneOffset()
-330
> process.env.TZ = 'Europe/Amsterdam'
'Europe/Amsterdam'
> new Date().getTimezoneOffset()
-330

Is there anything i am missing?

Yes there is node-time available, but shouldn't this be part of node.js framework.

Also I could also set the timezone of my server to UTC and make it work.

I may be wrong as well, but its something i have easily handled in PHP or C# and come to expect of it in any server side environment.

Thanks for the help.
--
@pvsundarram

Laurie Harper

unread,
Jul 29, 2011, 3:53:14 AM7/29/11
to nod...@googlegroups.com
Node isn't PHP or C#; those platforms include large standard libraries. Node provides a small, focused, low level API centered around networking and IO. Modules are the right place to implement higher level concerns like robust time/date/calendar functions.

It looks like there are all sorts of modules in the npm registry you may find useful (try `npm search date` or `npm search time` for example). 

L.

--
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


dale tan

unread,
Jul 29, 2011, 8:07:01 AM7/29/11
to nod...@googlegroups.com
i'm not sure how well this module handles timezones, but you can try the "npm search dateformat" module.  it is based off of some other date format libs for other languages.  it works pretty well for what i've used it form.
-- 
CONFIDENTIALITY NOTICE: This e-mail transmission, and any documents, files or previous e-mail messages attached to it may contain confidential
information that is legally privileged and is intended for the designated
recipient only. If you have received it in error, please notify the sender
immediately and delete the original. Any other use of the email by you is
STRICTLY PROHIBITED.

dale tan

unread,
Jul 29, 2011, 8:08:05 AM7/29/11
to nod...@googlegroups.com
here is the github page for said module:

Egor Egorov

unread,
Aug 2, 2011, 7:46:21 AM8/2/11
to nod...@googlegroups.com


On Friday, July 29, 2011 4:37:53 AM UTC+3, Sundarram P.V. wrote:
Is there anything i am missing?

Yes. process.env.TZ must be set before ANY date manipulations, otherwise it won't work due to some specific issues in libc. 

> float:~ egor$ node
>  new Date().getTimezoneOffset()
-180

float:~ egor$ node
> process.env.TZ='America/New_York';
'America/New_York'
>  new Date().getTimezoneOffset()
240

Nathan Rajlich

unread,
Aug 2, 2011, 12:53:49 PM8/2/11
to nod...@googlegroups.com
Check out my node-time[0] module. It has a special Date object that has a setTimezone() function. Enjoy!

David Bern

unread,
Aug 10, 2011, 12:17:03 PM8/10/11
to nodejs
I am having trouble with Time Zones on Windows. I have a list of
timestamps generated by a program that are in the local time zone and
I need to convert them to unix timestamps. But I can't get or change
the timezone of any date object in Node.js. Changing process.env.TZ
has no effect. The Date.js library doesn't work correctly either.

> new Date().getTimezoneOffset()
0

Calling Date.today().getTimezone() from the Date.js library works fine
in the browser, but it gives an error in Node.js <http://
code.google.com/p/datejs/wiki/APIDocumentation#getTimezone>.

Any help here would be much appreciated.

Thank you,
David Bern

PV Sundarram

unread,
Aug 10, 2011, 4:38:06 PM8/10/11
to nod...@googlegroups.com
launch node using
TZ='UTC' node server.js

it uses UTC as the timezone.
If you need to do calculations and store their timezone then going for one of the datetime extension libraries nodetime, node-timezone will help.
--
@pvsundarram



Reply all
Reply to author
Forward
0 new messages