time模块是python的内置模块
time模块是python的内置模块
获得当前时间time.time
python时间戳取整为10位,单位为s
import time
print(time.time()) # 1621235477.11
print(int(time.time())) # 1621235477
获取时间元组time.localtime
#显示当前时间的时间元组
print(time.localtime())
print(time.localtime(time.time())) # 同time.localtime()
休眠time.sleep
time.sleep(3)
每隔一段时间执行一个命令
with open(PATH,'r',encoding = 'utf-8') as file:
for line in file:
print(line,end='')
time.sleep(1)
获得时间的格式化字符串
import time
t2 = time.strftime('%Y-%m-%d %X')
print(t2)
# 2019-08-11 16:55:46