how to know the timezone name from utc time offset in javascript

六月ゝ 毕业季﹏ 提交于 2020-12-15 07:09:10

问题


How to know the timezone name from UTC offset in Javascript.

I have UTC offset, say

UTC+5:30, 

I need to know where this timezone location is, like I want to get 'Asia/Calcutta'.

If I give 'UTC+9' , then I need to get Asia/Tokyo

How to do this in Javascript?


回答1:


You should be able to get that using Intl API. You can find the demo at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions




回答2:


You can try that:

console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)


来源:https://stackoverflow.com/questions/54473715/how-to-know-the-timezone-name-from-utc-time-offset-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!