Convert UTC to Local Time in Python using Various Methods

Convert UTC to Local Time in Python using Various Methods

Python is a popular programming language. There are many inbuilt functions and modules that can make your task easier. The datatime module is one of them. It allows you to manipulate date and time. In this entire tutorial, you will know how to convert UTC to Local Time in Python using various methods.

Methods to Convert UTC to Local Time in Python

In this section, you will know all the methods to convert UTC to local time. Please be sure that you should do all your work on Jupyter Notebook as I am also doing on it. It’s for a better understanding of the output and the code.

Method 1: Using astimezone() function

The first method is the use of astimezone() function. It will use in combination with the tzlocal module. Execute the below lines of code.

from datetime import datetime
from import tzutc, tzlocal

utc =
print('UTC TIME: ' + str(utc))

local = utc.astimezone(tzlocal())
print('Local TIME: ' + str(local))

Explanation of the code

Here first Import dateime,tzutc and tzlocal python module. After that using the, I am getting the current UTC date and time. To convert the UTC time to local time I am using the dot operator on UTC time and passing the tzlocal() method inside the astimezone() function. When you will run the code you will get the following output.

Convesion of utc to local time using as astimezone function
Convesion of utc to local time using as astimezone function

Method 2: Convert UTC to Local Time using datetime only

The second method to convert is using the datetime module only. Here you will also use the pytz.timezone() function with the local time zone as an argument. You can get all the time zone list using the pytz.all_timezones. For example, in my case, I am using Asia/Kolkata Timezone. Copy and paste the below lines of code and see the output.

import datetime
from datetime import datetime
utc_datetime =
local_timezone = pytz.timezone('Asia/Kolkata')
local_datetime = local_datetime.astimezone(local_timezone)


Convesion of utc to local time using as datetime module
Conversion of UTC to local time using as datetime module


UTC to datetime
UTC to datetime

These are the methods I have compiled to convert Convert UTC to Local Time in Python. You can use any method you want as per convenience. I hope you have liked this tutorial. If you have any queries then you can contact us for more help and information.

Other Datetime Related Post –

Attributeerror: can only use .dt accessor with datetimelike values ( Solved)

Attributeerror: module datetime has no attribute strptime ( Solved )

Numpy datetime64 to datetime and Vice-Versa implementation

How to Convert Column to Datetime in pandas : Only 3 Steps

AttributeError: dataframe object has no attribute to_datetime ( Solved )



Python dateime


Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner