How to use timezone offset in Nodejs?

I need the following thread:

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 a possibility in nodejs utils api?

+20
javascript timezone datetime
May 16 '12 at 9:36
source share
5 answers

You can use node-time as below:

 var time = require('time'); var a = new time.Date(1337324400000); a.setTimezone('Europe/Amsterdam'); console.log(a.toString()); // Fri May 18 2012 09:00:00 GMT+0200 (CEST) a.setTimezone('Europe/Kiev'); console.log(a.toString()); // Fri May 18 2012 10:00:00 GMT+0300 (EEST) 
+30
May 30 '12 at 23:47
source share

Moment.js now has a Moment Time Zone

Install

 npm install --save moment-timezone 

Using

 var Moment = require('moment-timezone'); Moment().tz('America/Los_Angeles').format(); 
+12
Mar 17 '14 at 5:10
source share

UPDATE: now there is one more :) https://github.com/mde/timezone-js

Timezone replacement for JavaScript JavaScript dates. The timezoneJS.Date object is API compatible with JS dates, with the same getter and setter methods - it should work fine in any code that works with normal JavaScript dates.




no no

But you can use moment.js to simplify http://momentjs.com/docs/

You still need to know each offset, so you need a comparison, for example {"Europe/Amsterdam":2,"Europe/Kiev":3}

+6
May 16 '12 at 14:53
source share

See the timezone package in npm. It has everything you need, built-in and pure JS, and apparently this is the best time zone processing library.

https://www.npmjs.com/package/timezone

http://bigeasy.imtqy.com/timezone/

 var tz = require('timezone/loaded'), equal = require('assert').equal, utc; // 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 MicroJS library in pure JavaScript with no dependencies, which provides a mathematical date and time formatting for time dates.
  • The time zone uses the IANA database to determine the correct time for the wall clock anywhere in the world at any time from the start of the standard time.
  • Timezone date formats with full implementation of strftime formats, including GNU date extensions.
  • The time zone represents time in POSIX and local time using RFC 3999 date strings.
  • Timezone is a fully-featured standards-based time library in pure JavaScript for less than 3,000 minified and gzipped.
+1
Mar 08 '15 at 19:23
source share

Use moment-timezone.js, this is the best option for parsing, checking and changing the time in different time zones.

0
Jun 08 '15 at 4:39 on
source share



All Articles