What is the datetime.ctime() function in python?

The datetime.ctime() method from datetime module is used to convert data and time values into a string value.

Thedatetime module in Python is used to manipulate dates and times.

Syntax


datetime.ctime()

Parameters

It does not take any argument value.

Return Value

String: It returns a string containing date and time values.

Example

In the example below, we are converting date= 2021, 11, 24 and date= 2022, 7, 12 to string values. Execute to see the output strings.

from datetime import date
# demo date= 24/11/2021
Str= date(2021, 11, 24).ctime()
print("Value as string: ", Str)
# demo date= 12/07/2021
Str= date(2022, 7, 12).ctime()
print("Value as string: ", Str)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources