How to use timezone offset in Nodejs?

前端 未结 5 1095
迷失自我
迷失自我 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:42

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

    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 http://momentjs.com/docs/

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

提交回复
热议问题