How can I get the timezone name in JavaScript?

后端 未结 8 1644
时光取名叫无心
时光取名叫无心 2020-12-12 15:37

I know how to get the timezone offset, but what I need is the ability to detect something like \"America/New York.\" Is that even possible from JavaScript or is that somethi

8条回答
  •  情话喂你
    2020-12-12 15:55

    The Internationalization API supports getting the user timezone, and is supported in all current browsers.

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

    Keep in mind that on some older browser versions that support the Internationalization API, the timeZone property is set to undefined rather than the user’s timezone string. As best as I can tell, at the time of writing (July 2017) all current browsers except for IE11 will return the user timezone as a string.

提交回复
热议问题