Get Current Date and Time in Python



In this article, we will show you how you can get the current time and date in Python with the help of different functions. Here are the different ways to get the current Date and Time using the Datetime Module -

Using the Time Module -

Now we will discuss each of the above methods in the section below with examples -

Using the Datetime Module

Date and time are not data types in Python, but you can work with them using the DateTime module. The Datetime module is included in Python, so there is no need to install it separately.

Using the now() Method

First, we will use the now() method to get the current date and time. It returns the current local date and time.

Here is an example to show the usage of now() method to get the current date and time in Python -

import datetime

# Get the current date and time
now = datetime.datetime.now()

# Print the current date and time
print("Current date and time:", now)

# Print the current date
print("Current date:", now.date())

# Print the current time
print("Current time:", now.time())

# Print the current year
print("Current year:", now.year)

# Print the current month
print("Current month:", now.month)

This will create the following outcome -

Current date and time: 2025-05-08 14:50:20.666835
Current date: 2025-05-08
Current time: 14:50:20.666835
Current year: 2025
Current month: 5

Using the today() Method

In the below Python program, we will use the today() method to get the current date and time. The method returns the current local date and time.

Here is an example to show the usage of the today() method to get the current date and time in Python -

import datetime
# Get the current date and time
today = datetime.datetime.today()

# Print the current date and time
print("Current date and time:", today)

# Print the current date
print("Current date:", today.date())

# Print the current time
print("Current time:", today.time())

# Print the current year
print("Current year:", today.year)

# Print the current month
print("Current month:", today.month)

# Print the current day
print("Current day:", today.day)

This will generate the following result -

Current date and time: 2025-05-08 14:51:18.615349
Current date: 2025-05-08
Current time: 14:51:18.615349
Current year: 2025
Current month: 5
Current day: 8

Current Date and Time in UTC Format

Now we will show you how you can display the date and time in UTC format. The UTC format is a standard format for representing date and time.

See the example below to get the current date and time in UTC format using the datetime module -

import datetime

# Get the date and time in UTC format
utc_now = datetime.datetime.utcnow()

# Date and time in UTC format
print("Current date and time in UTC format:", utc_now)

This will produce the following result -

Current date and time in UTC format: 2025-05-08 09:24:45.515400

Current Date and Time in ISO Format

In this example, we will show you how to get the current date and time in ISO format. The ISO format is a standard format for representing date and time.

Following is a program to get the current date and time in ISO format using the datetime module -

import datetime

# Get the date and time in ISO format
iso_now = datetime.datetime.now().isoformat()

# Print in ISO format
print("Current date and time in ISO format:", iso_now)

This will lead to the following outcome -

Current date and time in ISO format: 2025-05-08T14:56:12.423234

Using the Time Module

The time module provides various time-related functions. The time module is also included in Python, so there is no need to install it separately. To get the current date and time, use the time module's time() function. This function returns the current local date and time.

Using the time.strftime() Method

Here we will use the time.strftime() method to get the current date and time. The strftime() method returns the current local date and time in a formatted string.

Let us see an example of how to use the time.strftime() method to get the current date and time in Python -

import time

# Get the current date and time
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

# Print the current date and time
print("Current date and time:", current_time)

The result of this Python program is -

Current date and time: 2025-05-08 14:57:30

Using the time.time() Method

In this example, we will use the time() method to get the current date and time. The time() method returns the current local date and time in seconds.

Here is an example of how to use the time() method to get the current date and time in Python -

import time

# Get the current date and time
current_time = time.time()

# Print the current date and time
print("Current date and time:", current_time)

# Convert the current time to a readable format
readable_time = time.ctime(current_time)

# Print the current date and time
print("Current date and time in a readable format:", readable_time)

When you run the program, it will show this output -

Current date and time: 1746696618.996939
Current date and time in a readable format: Thu May  8 15:00:18 2025

Current Date and Time in GMT Format

In this example, we will show you how to get the current date and time in GMT format. The GMT format is a standard format for representing date and time.

Here is an example of how to get the current date and time in GMT format using the time module -

# Import time module
import time

# Get the current date and time in GMT format
gmt_time = time.gmtime()

# Print the current date and time in GMT format
print("Current date and time in GMT format:", gmt_time)

After running the program, you will get this result -

Current date and time in GMT format: time.struct_time(tm_year=2025, tm_mon=5, tm_mday=8, tm_hour=9, tm_min=32, tm_sec=31, tm_wday=3, tm_yday=128, tm_isdst=0)
Updated on: 2025-06-11T14:38:02+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements