當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python time.clock_settime_ns()用法及代碼示例


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



相關用法


注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | time.clock_settime_ns() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。