通过javascript从浏览器获取Olson时区ID信息 [英] Getting Olson timezone ID information from browser via javascript

查看:117
本文介绍了通过javascript从浏览器获取Olson时区ID信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Javascript / PHP和时区

有可能获得Olson来自客户机器上的javascript的时区id,例如(美国/纽约)。我知道PHP可以通过timezone对象来实现,就像这样。 $ timezone->的getLocation(); JS是否存在类似的功能?

It is possible to get the Olson timezone id from javascript on the client's machine e.g. (America/New York). I know that PHP can do this via the timezone object, something like this. $timezone->getLocation(); Does similar functionality exist for JS?

我知道您可以获取客户端的时区偏移量,如下所示:
var curdate = new Date();
var offset = curdate.getTimeZoneOffset();

I know that you can grab the timezone offset of the client as followed: var curdate = new Date(); var offset = curdate.getTimeZoneOffset();

但我需要更多由Olson Id提供的细化信息。感谢您的帮助。

But I need more granular information provided by the Olson Id. Thank you for your help.

推荐答案

您无法直接访问JavaScript中的时区。但是,您可以通过将常规和夏令时与区域数据库进行比较来衡量在几个不同特定日期报告的偏移,以推断出正在使用的时区。 一个jsTimezoneDetect库可以为您完成大部分工作。

You can't directly access timezone in JavaScript. You can, however, measure offsets reported at several different specific dates to deduce what exactly time zone is in use by comparing regular and daylight savings times to database of zones. There's a jsTimezoneDetect library that can do most of this work for you.

这篇关于通过javascript从浏览器获取Olson时区ID信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆