Get timezone by Country and Region

2019-01-12 08:41发布

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.

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.

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?

标签: c# timezone
3条回答
时光不老,我们不散
2楼-- · 2019-01-12 09:25

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.

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

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.

Hope it will help somebody.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-12 09:30

It's been a while since this question was asked, but might help others ..

When you are using a DatabaseReader Object from maxmind API in there has already an attribute location.timeZone you can retrieve it from the object returned by GeoIP Class, check out on API docs from maxmind.

查看更多
登录 后发表回答