如何在javascript中获取城市或国家的时区 [英] how to get time zone of city or country in javascript
问题描述
我使用 getTimezoneOffset()
来获取给定日期对象的偏移量(以分钟为单位).可以使用JavaScript获取城市或国家/地区的时区偏移量吗?
I use getTimezoneOffset()
to get the offset in minutes for a given date object. Is is possible to use javascript to get timezone offset of a city or a country?
例如:
var offset = getCityOffset("Miami"); // returns -240
推荐答案
否,javascript内置没有任何内容,可让您获取特定时区/城市的偏移分钟数.
No, there is nothing built-in to javascript which allows you to get the number of minutes to offset for specific time zones/cities.
getTimeZoneOffset
适用于当前浏览器的设置
MomentJS时区扩展具有某些此类功能,这当然依赖于MomentJS库.
MomentJS Timezone extensions has some of this sort of functionality, which is of course reliant on the MomentJS library.
如果您可以访问纬度/经度值,则Google提供时区API
If you have access to Lat/Long values, then google provide a timezone API
这篇关于如何在javascript中获取城市或国家的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!