Time
Time representation
Code
from datetime import time
Create
| Action |
Code |
Details |
|
From hms
|
time(hour, minute, second)
|
|
|
Current time
|
|
|
|
Time from any valid ISO 8601 time string
|
time.fromisoformat(time_str)
|
e.g. 23:59:01 |
|
From total seconds since start of day
|
(datetime.min + timedelta(seconds=7321.5)).time()
|
|
Constants
| Action |
Code |
Details |
|
Latest representable time
|
|
|
Test
| Action |
Code |
Details |
|
Is time
|
isinstance(x, datetime.time)
|
|
|
Same moment in time
|
|
Up to x.resolution precision (usually 1Ξs) |
|
Happens before y
|
|
|
|
Happens after y
|
|
|
| Action |
Code |
Details |
|
Hour
|
|
|
|
Minute
|
|
|
|
Second
|
|
|
|
Microsecond
|
|
|
|
Smallest representable time difference
|
|
|
Convert
| Action |
Code |
Details |
|
Total seconds
|
|
|
|
Format time as ISO 8601
|
|
e.g., 23:59:00 |
|
Format datetime as HH:mm
|
|
e.g., 23:59 |
|
Format datetime as HH:mm:ss
|
|
e.g., 23:59:00 |
|
Format readable datetime of consistent length
|
|
e.g., Sun Jan 1 23:59:00 2023 |
|
Named tuple
|
|
|