Get Current Time in Python (original) (raw)

Last Updated : 25 Oct, 2025

Given a requirement to get the current system time in Python, there are several ways to achieve this. Let’s explore them.

Using datetime.now() and strftime()

This method uses datetime module, which work with both date and time. datetime.now() fetches the current local date and time, while strftime() allows formatting the time into a readable string format.

Python `

from datetime import datetime now = datetime.now() t = now.strftime("%H:%M:%S") print("Current Time =", t)

`

Output

Current Time = 14:17:03

**Explanation:

Using datetime.now() with pytz

This method is ideal when you want to get the current time for a specific time zone (for example, India, US, UK, etc.). The pytz module provides accurate and up-to-date timezone definitions that help display the correct time across regions.

Python `

from datetime import datetime import pytz

tz = pytz.timezone('Asia/Kolkata') dt = datetime.now(tz) print("India Time:", dt.strftime("%H:%M:%S"))

`

Output

India Time: 19:49:44

**Explanation:

Using time module

The time module provides functions to work with time values in seconds and to format them into readable formats. It is mainly used for timing operations or measuring code execution durations.

Python `

import time t = time.localtime() c = time.strftime("%H:%M:%S", t) print("Current Time:", c)

`

Output

Current Time: 14:21:55

**Explanation: