Tuesday, 17 September 2013

handling time zone in a countdown plugin

handling time zone in a countdown plugin

i have countdown plugin which takes a timestamp(in seconds) as an argument
and returns a countdown to the given timestamp in form of
day/houers/minutes .
all timestamps are calculated/stored in UTC timezone ... plugin used to
work fine until i have changed my server and currently my server is in
Newyork time zone .
as you can guess my countdown plugin doens't work right anymore ...
here is the important part of the plugin
// Time left
time_left = Math.floor((options.timestamp - (new Date())) / 1000);
is there any way change time zone on fly like in php ? something like
time_left = Math.floor((options.timestamp - (new Date('UTC'))) / 1000);

No comments:

Post a Comment