在Python中,time模塊提供了處理時間的函數和類。以下是一些time模塊的常用函數及其用法示例:
import time
timestamp = time.time()
print("當前時間戳:", timestamp)
import time
timestamp = time.time()
time_tuple = time.gmtime(timestamp)
print("時間元組:", time_tuple)
import time
time_tuple = (2021, 5, 20, 12, 30, 0, 3, 140, 0)
timestamp = time.mktime(time_tuple)
print("時間戳:", timestamp)
import time
time_tuple = (2021, 5, 20, 12, 30, 0, 3, 140, 0)
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)
print("格式化時間:", formatted_time)
import time
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print("當前時間:", current_time)
這些是time模塊中的一些常用函數的使用方法,可以根據具體需求選用適當的函數來處理時間。