Python Glossary Русский

all Python 3datetimeterm

time object

time

A time object (with no date). Hours, minutes, seconds and microseconds.

Syntax

from datetime import time
time(hour, minute, second, microsecond)

time supports no arithmetic: adding a timedelta raises TypeError — to shift a moment by half an hour, build a full datetime with datetime.combine(date, time) and do the math there. Every argument is optional and defaults to zero, the object is immutable, and comparisons work, ordering by hour, minute, second and microsecond.

Examples

from datetime import time
t = time(14, 30, 45)
print(t)  # → 14:30:45
print(t.hour, t.minute, t.second)  # → 14 30 45
t2 = time(0, 0, 0)
print(t2)  # → 00:00:00
print(time.fromisoformat('12:30:00'))  # → 12:30:00
print(time(23, 59, 59, 999999))  # → максимум дня

See also

Open in the full glossarydocs.python.orgReport an inaccuracy