all Python 3timeterm
time
module
Time as seconds since the epoch, sleep pauses, precise timers for measuring, and struct_time conversion.
Syntax
import time
time works with OS-level time: time.time gives seconds since the epoch, sleep pauses. Measure durations with perf_counter or monotonic: time.time can jump when the system clock is adjusted. For dates, time zones and date arithmetic datetime is more convenient, while time.strftime remains for simple formatting.
Examples
import time
start = time.perf_counter()
time.sleep(0.1)
print(time.perf_counter() - start >= 0.09) # → True
print(time.strftime('%Y-%m-%d', time.gmtime(0))) # → 1970-01-01
See also
Open in the full glossarydocs.python.orgReport an inaccuracy