Python 3.3+Linux · macOStimefunction
time.clock_settime()
POSIX clocks
Sets the system clock clk_id; only CLOCK_REALTIME is accepted. Unix: Linux and macOS, administrator rights required.
Syntax
time.clock_settime(clk_id, time)
It changes the time of the whole system, not of the program: an ordinary user gets PermissionError, and inside a container even root often does. Monotonic clocks cannot be set at all — OSError with errno 22 (EINVAL). Application code almost never needs it: to fake time in tests, stub the function instead.
Examples
import time
try:
time.clock_settime(time.CLOCK_MONOTONIC, 0.0)
except OSError as e:
print(e.errno) # → 22
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy