LczPtr 2019-12-28
import time # print("肉丝打卤面") # time.sleep(3) # 睡 3 s # print("鸡蛋西红柿打卤面") print(time.time()) # 1577465720.948886 print(time.localtime()) # time.struct_time(tm_year=2019, tm_mon=12, tm_mday=28, tm_hour=0, tm_min=55, tm_sec=20, tm_wday=5, tm_yday=362, tm_isdst=0) # time.strptime(string, format) 时间字符串 ---> 时间元组 s = "08-15-2019" t1 = time.strptime(s, "%m-%d-%Y") print(t1) # time.struct_time(tm_year=2019, tm_mon=8, tm_mday=15, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=227, tm_isdst=-1) # time.strftime(format, t) 时间元组 ---> 时间字符串 # 将时间元组t1 转换成 时间字符串 "19年08月15日" s1 = time.strftime("%y-%m-%d", t1) # 19-08-15 print(s1) # 19-08-15 # 时间戳 -- 时间元组之间的转换 t = time.time() res1 = time.gmtime(t) # 获取时间戳所对应的时间元组 UTC -- 格林尼治时间 res2 = time.localtime(t) # 获取时间戳所对应的时间元组 print(res1) # time.struct_time(tm_year=2019, tm_mon=12, tm_mday=27, tm_hour=16, tm_min=55, tm_sec=20, tm_wday=4, tm_yday=361, tm_isdst=0) print(res2) # time.struct_time(tm_year=2019, tm_mon=12, tm_mday=28, tm_hour=0, tm_min=55, tm_sec=20, tm_wday=5, tm_yday=362, tm_isdst=0) # 结构化时间 res3 = time.asctime(t1) res4 = time.ctime(t) print(res3) # Thu Aug 15 00:00:00 2019 print(res4) # Sat Dec 28 00:55:20 2019