How to use timezone offset in Nodejs?

前端 未结 5 1052
迷失自我
迷失自我 2020-11-27 17:26

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


        
5条回答
  •  北海茫月
    2020-11-27 17:47

    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.

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

    http://bigeasy.github.io/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 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.

提交回复
热议问题