Python Glossary Русский

all Python 3datetimefunction

datetime.datetime.timetuple()

datetime methods

Returns a time.struct_time — the structure time.mktime() accepts. Convenient for passing values to functions of the time module.

Syntax

datetime.timetuple() -> time.struct_time

This method exists for compatibility with the old time module: struct_time carries neither microseconds nor a time zone, so time.mktime(tt) will read the value as local time. For a naive object tm_isdst is -1 ("unknown"); for an aware one it comes from dst(). In new code timestamp(), astimezone() and strftime() usually cover the same ground more directly.

Examples

from datetime import datetime
import time
dt = datetime(2024, 6, 17, 10, 0)
tt = dt.timetuple()
print(tt.tm_year)  # 2024
print(tt.tm_wday)  # 0 (Monday)
ts = time.mktime(tt)  # unix timestamp

See also

Open in the full glossarydocs.python.orgReport an inaccuracy