Python-time库使用

import time
time.time():获取当前时间戳,即计算机内部时间,浮点数,1970年1月1日
time.ctime():获取当前时间,返回字符串
time.gmtime():获取当前时间,计算机可处理格式,struct

strftime(tpl,t)
tpl时间格式化的控制符:
%Y 年份
%m 月份
%B 月份缩写
%b 月份名称缩写
%日期
%A 星期,全拼
%a 星期,缩写
%H, 小时24小时制度
%I 小时12小时
%p 上午下午,PM,AM
%M,分钟
%S,秒

strptime(str,tpl):把字符串转换为计算机可处理时间格式,tpl为时间格式控制符

perf_counter():cpu级别的精确时间计数值,单位为s,计算差值
sleep(f):程序休眠f秒

import time
for i in range(100):
print("\r{:3}%".format(i),end="")
time.sleep(0.1)

\r:光标回到行首

发布了3 篇原创文章 · 获赞 0 · 访问量 104

猜你喜欢

转载自blog.csdn.net/yanfang7722/article/details/104100831