标签:转换 ring port 执行 计算 ftime for 参数 操作
1 import time 2 3 # print("肉丝打卤面") 4 # time.sleep(3) # 睡 3 s 5 # print("鸡蛋西红柿打卤面") 6 7 print(time.time()) # 1577465720.948886 8 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) 9 10 11 # time.strptime(string, format) 时间字符串 ---> 时间元组 12 s = "08-15-2019" 13 t1 = time.strptime(s, "%m-%d-%Y") 14 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) 15 16 # time.strftime(format, t) 时间元组 ---> 时间字符串 17 # 将时间元组t1 转换成 时间字符串 "19年08月15日" 18 s1 = time.strftime("%y-%m-%d", t1) # 19-08-15 19 print(s1) # 19-08-15 20 21 # 时间戳 -- 时间元组之间的转换 22 t = time.time() 23 res1 = time.gmtime(t) # 获取时间戳所对应的时间元组 UTC -- 格林尼治时间 24 res2 = time.localtime(t) # 获取时间戳所对应的时间元组 25 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) 26 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) 27 28 # 结构化时间 29 res3 = time.asctime(t1) 30 res4 = time.ctime(t) 31 print(res3) # Thu Aug 15 00:00:00 2019 32 print(res4) # Sat Dec 28 00:55:20 2019
标签:转换 ring port 执行 计算 ftime for 参数 操作
原文地址:https://www.cnblogs.com/Tree0108/p/12110225.html