To determine the time zone by city and country, you first need to get the latitude / longitude coordinates. There are several ways to do this, including various city databases, airport codes, or reverse geocoding addresses.
Keep in mind that there are cities in the world in which there are parts in which different time zones are observed. In these cases, you may have a slight margin of error. See this post: 2 time zones can be for 1 city?
Since you said that you were looking for the location of certain places (hotels), you probably would be better off geocoding the exact coordinates of each place using its full address. There are many services available for this, such as those provided by Google here .
Then use the coordinates in one of the services described here: How to get the time zone from a location using latitude and longitude coordinates?
If you have a time zone identifier, for example, Asia/Seoul or America/New_York , then you can use it in pytz functions, as the user falsetru showed in his answer.
You could speed up the process a bit by checking in advance whether the city you are interested in is one of those defined in the time zone database. But there are thousands of cities in the world more than just those key cities with time zone identifiers.
Other ideas
- You can use GeoDjango with the timezone map data found here .
- You can look at Django-GeoNames and see if time zones from GeoNames are included.
- There might be some other Django or Python specific library for this that I could not find in 5 minutes of searching on Google.
source share