how to use timezone offset in nodejs

how to use timezone offset in nodejs  using -'javascript,node.js,datetime,timezone'

I need the next flow:

var a = new Date(1337324400000, 'Europe/Amsterdam'); //+2h
console.log(a); // for example 12:00 Mon ...
a.setTimeZone('Europe/Kiev'); //+3h
console.log(a); // 13:00 Mon ...

Is there such possibility in nodejs utils api ?

asked Sep 18, 2015 by rajeshujade
0 votes

4 Answers

0 votes

You can use node-time, as follows:

var time = require('time');

var a = new time.Date(1337324400000);

console.log(a.toString()); // Fri May 18 2012 09:00:00 GMT+0200 (CEST)
console.log(a.toString()); // Fri May 18 2012 10:00:00 GMT+0300 (EEST)
answered Sep 18, 2015 by rajeevr642
0 votes

UPDATE: there is another one now:)

A timezone-enabled, drop-in replacement for the stock JavaScript Date. The timezoneJS.Date object is API-compatible with JS Date, with the same getter and setter methods -- it should work fine in any code that works with normal JavaScript Dates.

no there is not

But you can use moment.js to make it easier

You still need to know each offset so you will need mapping like {"Europe/Amsterdam":2,"Europe/Kiev":3}

answered Sep 18, 2015 by suyesh.lokhande
0 votes

See Timezone package in npm. It has everything needed built in and is pure JS and seems to be the best timezone handling library available.

var tz = require('timezone/loaded'),
    equal = require('assert').equal,

// Get POSIX time in UTC. 
utc = tz('2012-01-01');

// Convert UTC time to local time in a localize language. 
equal(tz(utc, '%c', 'fr_FR', 'America/Montreal'),
      'sam. 31 déc. 2011 19:00:00 EST');
  • Timezone is a MicroJS library in pure JavaScript with no dependencies that provides timezone aware date math and date formatting.
  • Timezone uses the IANA Database to determine the correct wall clock time anywhere in the world for any time since the dawn of standardized time.
  • Timezone formats dates with a full implementation of strftime formats, including the GNU date extensions.
  • Timezone represents time in POSIX time and local time using RFC 3999 date strings.
  • Timezone is a full featured standards based time library in pure JavaScript for under 3K minified and gzipped.
answered Sep 18, 2015 by maurya
0 votes

Moment.js now has Moment Timezone


npm install --save moment-timezone


var Moment = require('moment-timezone');
answered Sep 18, 2015 by sanjaypal1983