.ctime()

Anonymous contributor's avatar
Anonymous contributor
Published Apr 19, 2022
Contribute to Docs

The ctime() function takes a time, expressed in seconds since the epoch, and returns a formatted string.

Syntax

ctime(s)

The argument s is the number of seconds since the epoch. The epoch is defined as January 1, 1970, 00:00:00 UTC. If no argument is provided the function will use the current local time.

Example

The ctime() function can be used to translate a time in seconds (from the epoch) into a human-readable format:

import time
print(time.ctime(10000))
# Output: Thu Jan 1 02:46:40 1970

Codebyte Example

The ctime() function can be used to return the current local time.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy