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
pytz python library.
How to get the current time ?
In order to get the local time, we can use the time module. Some important functions of the time module
- localtime() – it helps to get the current local time
- strftime(“%H:%M:%S”, t) – it helps to decide the format of the time to be used to display the time
How to get current time in different zones ?
In order to get the current time of a particular timezone there is a need to use the
pytz Python library. Some of the important commands of pytz library are
- utc – it helps to get the standard UTC time zone
- timezone() – it helps to get the time zone of a particular location
- now() – it helps to get the date, time, utc standard in default format
- astimezone() – it helps to convert the time of a particular time zone into another time zone
We will get the local current time of the region and the standard UTC time
Output: UTC in Default Format : 2020-03-31 07:15:59.640418+00:00 IST in Default Format : 2020-03-31 12:45:59.692642+05:30 Date & Time in UTC : 2020:03:31 07:15:59 UTC+0000 Date & Time in IST : 2020:03:31 12:45:59 IST+0530
Comparing the UTC and IST format of time zones of different regions
Output: UTC Format IST Format 2020-03-31 11:21:13 UTC +0000 2020-03-31 16:51:13 IST +0530 2020-03-31 11:21:13 UTC +0000 2020-03-31 16:51:13 IST +0530 2020-03-31 11:21:13 UTC +0000 2020-03-31 16:51:13 IST +0530 2020-03-31 11:21:13 UTC +0000 2020-03-31 16:51:13 IST +0530 2020-03-31 11:21:13 UTC +0000 2020-03-31 16:51:13 IST +0530
Thus we can conclude that although different regions have different regional time zones but when converted to the UTC time zone all of them gave same value. Thus we can say that
- IST is +0530 hrs ahead of UTC
- EDT is -0400 hrs before of UTC
- SAST is +0200 hrs ahead of UTC
- CDT is -0500 hrs before of UTC
- EEST is +0300 hrs ahead of UTC
- Get current time in milliseconds using Python
- Get Current Date and Time using Python
- Python program to get Current Time
- Python program to find difference between current time and given time
- Python | Timezone Conversion
- Get parent of current directory using Python
- Get current date using Python
- Get current Gold price using Python
- Get current timestamp using Python
- Python - Get Today's Current Day using Speech Recognition
- Get directory of current Python script
- Python VLC MediaPlayer - Getting Current media time
- PYGLET – Get Current Media Texture in Player
- Python | Find current weather of any city using openweathermap API
- PyQt5 – Different padding size at different edge of Label
- PyQt5 - Setting different toolTip to different item of ComboBox
- Get Bit Coin price in real time using Python
- Create a GUI to get Sunset and Sunrise time using Python.
- How to get real-time Mutual Funds Information using Python?
- Python | Create an empty text file with current date as its name
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.