Get date time for a specific time zone using JavaScript

前端 未结 5 1621
孤城傲影
孤城傲影 2020-12-24 06:20

It seems that JavaScript\'s Date() function can only return local date and time. Is there anyway to get time for a specific time zone, e.g., GMT-9?

Combining @​Esail

5条回答
  •  有刺的猬
    2020-12-24 06:40

    You can do this in one line:

    let d = new Date(new Date().toLocaleString("en-US", {timeZone: "timezone id"})); // timezone ex: Asia/Jerusalem
    

提交回复
热议问题