Python 3.3+Linux · macOStimefunction
time.clock_gettime()
POSIX clocks
The reading of the chosen system clock clk_id in seconds (a float). Unix only: Linux and macOS.
Syntax
time.clock_gettime(clk_id) -> float
It is for when the standard clocks are not enough: on Linux CLOCK_BOOTTIME, unlike monotonic(), keeps running while a laptop is suspended, and CLOCK_PROCESS_CPUTIME_ID gives CPU time. For everyday tasks it is unnecessary: clock_gettime(CLOCK_MONOTONIC) is what monotonic() uses on Linux, and code calling it will not run on Windows.
Examples
import time
now = time.clock_gettime(time.CLOCK_REALTIME) # → ? на Windows AttributeError
print(abs(now - time.time()) < 1) # → True
print(time.clock_gettime(time.CLOCK_MONOTONIC)) # → ? 12345.678
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy