按国家和地区获得时区 [英] Get timezone by Country and Region

查看:305
本文介绍了按国家和地区获得时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个通讯报文发送C#/。NET平台的应用。我最近添加的模块由他的IP地址使用maxmind.com数据库检索收件人的国家和地区。

I'm developing an newsletter sending application on C#/.NET platform. I've recently added the module to retrieve the country and region of a recipient by his IP address using maxmind.com database.

例如,我可以得到一些样本IP地址如下信息:

For example, I can get the following info for some sample IP address:

Country Code: DE
Country Name: Germany   
Region Name:  Hessen 
City:         Frankfurt Am Main
Latitude:     50.1167
Longitude:    8.6833 

我现在需要的是利用这些信息来获取用户的时区。

What I need now is to get the user's time zone using this information.

我知道有一些还提供了时区的一些GEOIP的数据库,但我需要使用这个具体GEOIP数据库。此外,JavaScript的确定时间偏移方法不能用在这里。

I know there are some GeoIp databases that provide also the time zone, but I need to use this concrete GeoIp database. Also, javascript's approach to determine time offset can't be used here.

也许我可以使用的国家和地区名称获得某种程度上的时区?

May be I can get somehow the timezone using country and region name?

推荐答案

最后,长期的研究后,我已经找到了解决办法。它可能并不多的准确,但它并不需要远程服务的依赖性。

Finally, after long research, I've found the solution. It may not be much accurate, but it does not require the dependency of remote service.

我发现的MaxMind的数据库提供了地区和时区之间的映射文件从奥尔森数据库(又名TZ数据库): HTTP:/ /www.maxmind.com/timezone.txt

I've found that maxmind's database provides mapping file between regions and time zones from Olsen database (aka tz database): http://www.maxmind.com/timezone.txt

第二步是奥尔森时区转换成在.NET中时区。最适合的解决方案在这里找到:<一href=\"http://www.timdavis.com.au/data/olson-time-zone-database-to-standard-windows-time-zone-v01/\">http://www.timdavis.com.au/data/olson-time-zone-database-to-standard-windows-time-zone-v01/
所以,我已经编辑了一点,并将其转换为CSV文件,从.NET阅读。

The second step was to convert Olsen timezones in .NET timezones. The best suitable solution was found here: http://www.timdavis.com.au/data/olson-time-zone-database-to-standard-windows-time-zone-v01/ So I've edited it a bit and converted it to CSV file to read it from .NET.

希望这会帮助别人。

这篇关于按国家和地区获得时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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