Python Get Current time

In this article, we will learn to get the current time of your locale as well as different time zones in Python.

There are a number of ways we can take to get current time in Python.

  • Using the datetime object
  • Using the time module

Current time using the datetime object

from datetime import datetime

now =

current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)


Current Time = 07:41:19

In the above example, we have imported the datetime class from the datetime module.

Then, we used the now() function to get a datetime object containing current date and time.

Using datetime.strftime() function, we then created a string representing current time.

Current time using time module

In Python, we can also get the current time using the time module.

import time

t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)



Current time of a Certain timezone

If we need to find the current time of a certain timezone, you can use the pytZ module.

from datetime import datetime
import pytz

# Get the timezone object for New York
tz_NY = pytz.timezone('America/New_York') 

# Get the current time in New York
datetime_NY =

# Format the time as a string and print it
print("NY time:", datetime_NY.strftime("%H:%M:%S"))

# Get the timezone object for London
tz_London = pytz.timezone('Europe/London')

# Get the current time in London
datetime_London =

# Format the time as a string and print it
print("London time:", datetime_London.strftime("%H:%M:%S"))


NY time: 03:45:16
London time: 08:45:16

Here, we have used the pytz module to find the current time of a certain time zone.

Did you find this article helpful?