new Date() for a specific timezone in JavaScript

后端 未结 1 1260
别那么骄傲
别那么骄傲 2020-12-21 20:50

I am working on a project and I was just curious if it was possible in JavaScript to call new Date() for a specific timezone. When I say:

var test = new Dat         


        
相关标签:
1条回答
  • 2020-12-21 21:13

    Checkout moment-timezone.js which makes working with Dates and timezones a lot easier in javascript.

    The example on the frontpage shows how it works:

    var newYork    = moment.tz("2014-06-01 12:00", "America/New_York");
    var losAngeles = newYork.clone().tz("America/Los_Angeles");
    var london     = newYork.clone().tz("Europe/London");
    
    newYork.format();    // 2014-06-01T12:00:00-04:00
    losAngeles.format(); // 2014-06-01T09:00:00-07:00
    london.format();     // 2014-06-01T17:00:00+01:00
    
    0 讨论(0)
提交回复
热议问题