time.clock_settime_ns()
时间模块的方法用于设置指定时钟的时间(以纳秒为单位)clk_id
。本质上,clk_id是一个整数值,代表时钟的ID。这种方法类似于time.clock_settime()
用于设置指定时钟的时间的方法clk_id但几分之一秒。
用法: time.clock_settime_ns(clk_id, nanoseconds)
参数:
clk_id:clk_id常数或代表时钟clk_id的整数值。
返回类型:此方法不返回任何值。
代码:用于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
相关用法
- Python next()用法及代码示例
- Python os.dup()用法及代码示例
- Python set()用法及代码示例
- Python Decimal max()用法及代码示例
- Python PIL ImageOps.fit()用法及代码示例
- Python os.rmdir()用法及代码示例
- Python sympy.det()用法及代码示例
- Python Decimal min()用法及代码示例
- Python os.readlink()用法及代码示例
- Python os.writev()用法及代码示例
- Python os.readv()用法及代码示例
- Python PIL RankFilter()用法及代码示例
- Python os.rename()用法及代码示例
- Python os.sendfile()用法及代码示例
注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Python | time.clock_settime_ns() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。