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

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

问题描述

我正在 C#/.NET 平台上开发一个时事通讯发送应用程序.我最近添加了一个模块,用于使用 maxmind.com 数据库通过 IP 地址检索收件人的国家和地区.

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 的数据库提供了来自 Olsen 数据库(又名 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 时区.在这里找到了最合适的解决方案:https://www.timdavis.com/posts/olson-time-zone-database-to-standard-windows-time-zone-v0-1所以我对其进行了一些编辑并将其转换为 CSV 文件以从 .NET 中读取它.

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

希望它对某人有所帮助.

Hope it will help somebody.

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

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