Convert date to another timezone in JavaScript

后端 未结 24 3044
没有蜡笔的小新
没有蜡笔的小新 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:44

    You can use to toLocaleString() method for setting the timezone.

    new Date().toLocaleString('en-US', { timeZone: 'Indian/Christmas' })
    

    For India you can use "Indian/Christmas" and the following are the various timeZones,

    "Antarctica/Davis",
        "Asia/Bangkok",
        "Asia/Hovd",
        "Asia/Jakarta",
        "Asia/Phnom_Penh",
        "Asia/Pontianak",
        "Asia/Saigon",
        "Asia/Vientiane",
        "Etc/GMT-7",
        "Indian/Christmas"
    

提交回复
热议问题