问题描述
当我只有他们的IP地址时,是否可以找到用户所在的时区?我正在寻找我需要应用于服务器时间的时间偏移量,以便找到用户所在位置的时间.
Is there a way to find the time zone a user is in when all I have is their IP address? I'm looking for the time offset I need to apply to the server time in order to find the time for the user's location.
推荐答案
您需要尝试确定位置(距离100%的准确度还很远).看这个问题关于做到这一点.
You'll need to attempt to determine the location (which is far from 100% accurate). Seethis question about doing just that.
请参见此问题有关将邮政编码转换为时区的问题 (不过,这并不是100%的傻瓜证明).
See this question about translating a zip code into time zone (though that, again, is not 100% fool proof).
简短的版本是:很复杂.您必须使用第三方服务来维护IP掩码数据库的位置,然后使用在那里确定的位置来确定时区.
The short version is: it's complicated. You'll have to use a third-party service that maintains a database of IP masks to locations, then use the location determined there to determine the time zone.
让客户端在连接时仅发送时区(或UTC偏移)要可靠得多.
It's far more reliable to have the client simply send the time zone (or UTC offset) when it connects.
如果这是一个Web应用程序,请参见有关使用JavaScript进行操作的另一个问题.确定客户所在的时区.
If this is a web application, see one more question about using JavaScript to determine the client time zone.
这篇关于从IP地址查找时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!