Python Glossary Русский

all Python 3timefunction

time.asctime()

time conversion

Turns a struct_time into a fixed-form string like 'Sun Jun 20 23:21:05 1993'; without an argument it uses localtime().

Syntax

time.asctime([time_tuple])

The format is hard-wired and ignores the locale: names are always English, a single-digit day is padded with a space ('Jun 9'), and the string is hard to sort or parse. For logs and files strftime('%Y-%m-%d %H:%M:%S') or isoformat() is better. Unlike the C function of the same name there is no trailing newline.

Examples

import time
print(time.asctime(time.gmtime(0)))  # → Thu Jan  1 00:00:00 1970
print(time.asctime())  # → ? Wed Oct  7 12:00:00 2026

See also

Open in the full glossarydocs.python.orgReport an inaccuracy