Python| time.clock_settime_ns() 方法
Time 模块的time.clock_settime_ns()
方法用于设置指定时钟clk_id
的时间(以纳秒为单位)。基本上, clk_id是一个整数值,表示时钟的 id。此方法类似于time.clock_settime()
方法,用于设置指定时钟clk_id的时间,但以小数秒为单位。
Syntax: time.clock_settime_ns(clk_id, nanoseconds)
Parameters:
clk_id: A clk_id constant or an integer value representing clk_id of the clock.
Return type: This method does not return any value.
代码: time.clock_settime_ns()
方法的使用
# Python program to explain time.clock_settime_ns() 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 nanoseconds)
# using time.clock_gettime_ns() method
t = time.clock_gettime_ns(clk_id)
print("Current value of system-wide real-time clock: % d nanoseconds" % t)
# Set the new value of
# time (in nanoseconds) for
# System-wide real-time clock
# using time.clock_settime_ns() method
nanosecs = 10000000
time.clock_settime(clk_id, nanosecs)
print("\nTime modified")
# Get the modified value of
# system-wide real-time clock (in nanoseconds)
# using time.clock_gettime_ns() method
t = time.clock_gettime_ns(clk_id)
print("\nCurrent value of system-wide real-time clock: % d nanoseconds" % t)
输出:
Current value of system-wide real-time clock: 1568621304462590132 nanoseconds
Time modified
Current value of system-wide real-time clock: 10000000000180111 nanoseconds
参考: https://docs。 Python.org/3/library/time.html#time.clock_settime_ns