Convert date to another timezone in JavaScript

后端 未结 24 3036
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 04:45

I am looking for a function to convert date in one timezone to another.

It need two parameters,

  • date (in format \"2012/04/10 10:10:30 +0000\")
24条回答
  •  执笔经年
    2020-11-21 05:22

    var aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"});
    console.log('AEST time: '+ (new Date(aestTime)).toISOString())
    
    var asiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Shanghai"});
    console.log('Asia time: '+ (new Date(asiaTime)).toISOString())
    
    var usaTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});
    console.log('USA time: '+ (new Date(usaTime)).toISOString())
    
    var indiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
    console.log('India time: '+ (new Date(indiaTime)).toISOString())

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

提交回复
热议问题