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


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


time.clock_settime()“時間”模塊的方法用於設置指定時鍾clk_id的時間(以秒為單位)。本質上,clk_id是一個整數值,代表時鍾的id。

用法: time.clock_settime(clk_id, seconds)

參數:
clk_id:clk_id常數或代表時鍾clk_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



相關用法


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