📜  Python| time.clock_settime() 方法

📅  最后修改于: 2022-05-13 01:55:09.104000             🧑  作者: Mango

Python| time.clock_settime() 方法

Time 模块time.clock_settime()方法用于设置指定时钟 clk_id 的时间(以秒为单位)。基本上, clk_id是一个整数值,表示时钟的 id。

代码: time.clock_settime()方法的使用

# Python program to explain time.clock_settime() method
  
# importing time module
import time
  
  
# clk_id for System-wide real-time clock
clk_id = time.CLOCK_REALTIME
  
  
# Get the current value of
# system-wide real-time clock (in seconds)
# using time.clock_gettime() method
t = time.clock_gettime(clk_id) 
  
print("Current value of system-wide real-time clock: % d seconds" % t)
  
# Set the new value of
# time (in seconds) for
# System-wide real-time clock
# using time.clock_settime() method
seconds = 10000000
time.clock_settime(clk_id, seconds)
  
print("\nTime  modified")
  
  
# Get the modified value of
# system-wide real-time clock (in seconds)
# using time.clock_gettime() method
t = time.clock_gettime(clk_id) 
print("\nCurrent value of system-wide real-time clock: % d seconds" % t)
输出:
Current value of system-wide real-time clock: 1568589568 seconds

Time  modified

Current value of system-wide real-time clock: 10000000 seconds

参考: https://docs。 Python.org/3/library/time.html#time.clock_settime