time库的使用
time库包括三类函数
•时间获取
- time(),ctime(),gmtime()
- 时间格式化:strftime() strptime()
- 程序计时:sleep(),perf_counter()
# %Y年份 %m月份 %B月份名称 %b月份名简写 %d日期 # %A星期 %a星期简写 %H24制时间 %I12小时制时间 # %M分钟 %p上午下午 %S秒 import time as t start = t.perf_counter() print(t.time()) print(t.ctime()) print(t.gmtime()) time = t.gmtime() print(t.strftime("%Y-%m-%d %H:%M:%S",time)) timestr = "2021-01-25 12:35:21" print(t.strptime(timestr,"%Y-%m-%d %H:%M:%S")) #程序休眠1秒 t.sleep(1) end = t.perf_counter() stay = end - start print("共运行{}秒".format(stay))