# 时间模块 import time # 获取当前时间戳 res = time.time() print(res) # 1569152220.355634 # 获取当前时间 res = time.ctime() print(res) # Sun Sep 22 19:38:40 2019 # 格式化时间戳 res = time.ctime(1569152220.355634) print(res) # Sun Sep 22 19:37:00 2019 # 获取本地时间元组 res = time.localtime() print(res) # time.struct_time(tm_year=2019, tm_mon=9, tm_mday=22, tm_hour=19, tm_min=40, tm_sec=34, tm_wday=6, tm_yday=265, tm_isdst=0) # 通过元组获取时间戳 res = time.mktime(( 2019, 9, 28, 10, 10, 10, 0, 0, 0)) print(res) # 1569636610.0 # 通过时间元组 获取 时间字符串 res = time.asctime(( 2019, 9, 28, 10, 10, 10, 0, 0, 0)) print(res) # Mon Sep 28 10:10:10 2019 # sleep 睡眠等待 # time.sleep(2) # 单位为秒数 print('睡醒了吗?') # strftime(格式化字符串,时间元组) 格式化字符串 res = time.strftime('现在是%Y年%m月%d日%H点%M分%S秒',time.localtime()) print(res) # strptime() 将字符串里面的时间提取出来 res = time.strptime('现在是2019年09月22日20点01分59秒','现在是%Y年%m月%d日%H点%M分%S秒') print(res) # time.struct_time(tm_year=2019, tm_mon=9, tm_mday=22, tm_hour=20, tm_min=1, tm_sec=59, tm_wday=6, tm_yday=265, tm_isdst=-1) # perf_counter() 用于计算程序运行时间 start_time = time.perf_counter() n = 0 while n < 999: n+=1 end_time = time.perf_counter() print(end_time - start_time)
版权属于:
emer
文章声明:
本文版权内容属于《快乐小窝》转载请标明出处
评论一下?