all Python 3datetimeterm
datetime.time
time
A time of day (hour, minute, second, microsecond) without a date.
Syntax
datetime.time(hour=0, minute=0, second=0)
time has no arithmetic: you cannot subtract two times or add a timedelta to one — combine it with a date first (datetime.combine) and do the maths on the datetime. Comparison works but misleads across midnight: 23:30 sorts above 00:10 even though it comes first in an overnight span like 23:30-00:10. The object is immutable, so build a changed copy with replace().
Examples
import datetime
t = datetime.time(10, 30, 45)
print(t) # → 10:30:45
print(t.hour, t.minute) # → 10 30
See also
Open in the full glossarydocs.python.orgReport an inaccuracy