The Wayback Machine - https://web.archive.org/web/20240917114106/https://www.geeksforgeeks.org/get-time-zone-of-a-given-location-using-python/
Open In App

Get Time Zone of a Given Location using Python

Last Updated : 17 May, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we are going to see how to get the time zone from a given location. The Timezonefinder module is able to find the timezone of any point on earth (coordinates) offline. Before starting we need to install this module.

Modules Needed

  1. timezonefinder: This module does not built in with Python. To install this type the below command in the terminal.
pip install timezonefinder
  •  Geopy: .geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the world. To install the Geopy module, run the following command in your terminal.
pip install geopy

Let’s understand this module with Step by step:

Step 1: import TimezoneFinder module

Python3




from timezonefinder import TimezoneFinder


Step 2:  make an object of TimezoneFinder.

Python3




# object creation
obj = TimezoneFinder()


Step 3: Pass the latitude and longitude in a timezone_at() method and it return the time zone of a given location.

Python3




# pass the longitude and latitude
# in timezone_at and
# it return time zone 
latitude = 25.6093239
longitude = 85.1235252
obj.timezone_at(lng=latitude, lat=longitude)


Output:

'Asia/Kolkata'

Now let write a script to get timezone with a specific location.

Approach:

  • Import the module
  • Initialize Nominatim API to get location from the input string.
  • Get  latitude and longitude with geolocator.geocode() function.
  • Pass the latitude and longitude in a timezone_at() method and it returns the time zone of a given location.

Code:

Python3




# importing module
from geopy.geocoders import Nominatim
from timezonefinder import TimezoneFinder
  
# initialize Nominatim API
geolocator = Nominatim(user_agent="geoapiExercises")
  
# input as a geek
lad = "Dhaka"
print("Location address:", lad)
  
# getting Latitude and Longitude
location = geolocator.geocode(lad)
  
print("Latitude and Longitude of the said address:")
print((location.latitude, location.longitude))
  
# pass the Latitude and Longitude
# into a timezone_at
# and it return timezone
obj = TimezoneFinder()
  
# returns 'Europe/Berlin'
result = obj.timezone_at(lng=location.longitude, lat=location.latitude)
print("Time Zone : ", result)


Output:

Location address: Dhaka
Latitude and Longitude of the said address:
(23.810651, 90.4126466)
Time Zone :  Asia/Dhaka


Similar Reads

Get Zip Code with given location using GeoPy in Python
In this article, we are going to write a python script to get the Zip code by using location using the Geopy module.geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the world. To install the Geopy module, run the following command in your terminal. pip install geopy Approach:
2 min read
Python | Reverse Geocoding to get location on a map using geographic coordinates
Reverse geocoding is the process of finding a place or a location address from a given pair of geographic coordinates(latitude and longitude).Modules needed: reverse_geocoder: A Python library for offline reverse geocoding. pprint: A module which helps to "pretty-print" any arbitrary python data structure. Installation: The modules can be easily in
1 min read
Get Location of Python site-packages Directory
A Python installation has a site-packages directory inside the module directory. This directory is where user-installed packages are dropped. A .pth file in this directory is maintained, which contains paths to the directories where the extra packages are installed. In this article, you will learn how to find the location of Python's site-packages
2 min read
Time difference between expected time and given time
Given the initial clock time h1:m1 and the present clock time h2:m2, denoting hour and minutes in 24-hours clock format. The present clock time h2:m2 may or may not be correct. Also given a variable K which denotes the number of hours passed. The task is to calculate the delay in seconds i.e. time difference between expected time and given time. Ex
5 min read
Pandas Series dt.time | Extract Time from Time Stamp in Series
The Series.dt.time attribute returns a NumPy array containing time values of the timestamps in a Pandas series. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx sr = pd.to_datetime
2 min read
Find the location with specified latitude and longitude using Python
In this article, we are going to write a python script to find the address of a specified latitude and longitude using the geopy module. The geopy module makes it easier to locate the coordinates of addresses, cities, countries, landmarks, and zipcode. Installation: To install GeoPy module, run the following command in your terminal. pip install ge
1 min read
How to Automate VPN to change IP location on Ubuntu using Python?
To Protect Our system from unauthorized users Access you can spoof our system's IP Address using VPN service provided by different organizations. You can set up a VPN on your system for free. After you set up and log in to the VPN over the Ubuntu system you need to manually connect with different VPN servers after some duration. We can automate it
3 min read
PYGLET – Opening file using File Location
In this article we will see how we can open a file using file location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set t
3 min read
location element method - Selenium Python
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What
2 min read
Python Tweepy - Getting the location of a user
In this article we will see how we can get the location of a user. The location of the user account need not be the exact physical location of the user. As the user is free to change their location, the location of the account can even by a hypothetical place. The location attribute is optional and is Nullable. Identifying the location in the GUI :
2 min read
Find location of an element in Pandas dataframe in Python
In this article, we will see how to find the position of an element in the dataframe using a user-defined function. Let's first Create a simple dataframe with a dictionary of lists. How to find an element in Pandas Dataframe?In a Pandas DataFrame, you can find the position of a specific element or check for its existence using various methods. Here
3 min read
Statistical Functions in Python | Set 1 (Averages and Measure of Central Location)
Python has the ability to manipulate some statistical data and calculate results of various statistical operations using the file "statistics", useful in domain of mathematics. Important Average and measure of central location functions : 1. mean() :- This function returns the mean or average of the data passed in its arguments. If passed argument
3 min read
Python script to open a Google Map location on clipboard
The task is to create a python script that would open the default web browser to the Google map of the address given as the command line argument. Following is the step by step process:  Creating the Address_string from command line input : Command line arguments can be read through sys module. The sys.argv array has the first element as the filena
3 min read
Get Real-time Crypto Price Using Python And Binance API
In this article, we are going to see how to get the real-time price of cryptocurrencies using Binance API in Python. Binance API Binance API is a method that allows you to connect to the Binance servers using several programming languages. With it, you can automate your trading and make HTTP requests to send and receive data. Here we access Binance
2 min read
Get current time in milliseconds using Python
In this article, we will get the time in milliseconds using Python. Here, we are using two inbuild modules of Python that is Datetime module and the Time Module to get the time in milliseconds. Get time in milliseconds using the DateTime module To get the time in milliseconds we used the DateTime module, Firstly we printed the date time with second
2 min read
Get Current Time in different Timezone using Python
Timezone is defined as a geographical area or region throughout which standard time is observed. It basically refers to the local time of a region or country. Most of the time zones are offset from Coordinated Universal Time (UTC), the world's standard for time zone. In order to get the current time of different time zones, we will be using the pyt
4 min read
Get Bit Coin price in real time using Python
In this article we will see how we can get the current price of the bit coin. Bitcoin is a cryptocurrency. It is a decentralized digital currency without a central bank or single administrator that can be sent from user to user on the peer-to-peer bitcoin network without the need for intermediaries. Modules required and Installation: Requests : Req
2 min read
Create a GUI to get Sunset and Sunrise time using Python.
Prerequisite: Tkinter module In this article, we are going to write python scripts to get sunset and sunrise time and bind it with the GUI application. Before starting we need to understand suntime and geopy module Modules Needed: suntime module: This module will return the sunset and sunrise time calculation python library. Run this command in you
3 min read
How to get real-time Mutual Funds Information using Python?
In this article, we are going to write Python scripts to real-time Mutual Funds Information. Today Mutual Funds is a very popular term among investors, so let's do some help for them. Mftool Modules will help to collect real-time data from AFM(Association of Mutual Funds). Features of Mftool: Get last update quotes from Mutual Fund using scheme cod
3 min read
How to Get Current Date and Time using Python
In this article, we will cover different methods for getting data and time using the DateTime module and time module in Python. Different ways to get Current Date and Time using PythonCurrent time using DateTime objectGet time using the time moduleGet Current Date and Time Using the Datetime ModuleIn this example, we will learn How to get the curre
6 min read
NLP | Location Tags Extraction
Different kind of ChunkParserI subclass can be used to identify the LOCATION chunks. As it uses the gazetteers corpus to identify location words. The gazetteers corpus is a WordListCorpusReader class that contains the following location words: Country names U.S. states and abbreviations Mexican states Major U.S. cities Canadian provinces LocationCh
2 min read
PyQt5 QDockWidget – Dock Location Changed Signal
In this article we will see how we can get the dock location changed signal of the QDockWidget. QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow(original window). This signal is emitted when th
2 min read
PYGLET – Setting Window Location
In this article we will see how we can set the window location in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entir
2 min read
PYGLET – Getting Window current Location
In this article we will see how we can get the current location of window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fi
2 min read
PYGLET – Creating URL Location
In this article, we will see how we can create a URL location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia, etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill a
2 min read
PYGLET – Creating ZIP Location Object
In this article we will see how we can create a ZIP location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an
3 min read
PYGLET – Creating File Location
In this article we will see how we can create a file location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an
2 min read
PYGLET – Creating File Location
In this article we will see how we can create a file location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an
2 min read
PYGLET – Getting Location of Resource
In this article we will see how we can get resource location in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire
3 min read
How to change Seaborn legends font size, location and color?
Seaborn is a library for making statistical graphics on top of matplotlib with pandas data structures in python. Seaborn legend is the dialog box which is located on the graph which includes the description of the different attributes with their respected colors in the graph. We can easily change the properties of the seaborn legend including font
3 min read
Practice Tags :