1. time
- time.time() 获取当前时间戳
- time.localtime(time) 将时间戳转为time对象
- time.strftime(str,longtime) 将time对象转为字符串
- time.strptime(longtime,str) 将time对象转为字符串
1.1. 时间戳转换
import time
q=time.time() #获取当前时间戳
a=time.localtime(time.time()) #将时间戳转为time对象
#time.struct_time(tm_year=2021, tm_mon=4, tm_mday=29, tm_hour=21, tm_min=38, tm_sec=11, tm_wday=3, tm_yday=119, tm_isdst=0)
a= time.strftime("%Y-%m-%d %H:%M:%S", a) #将time对象转为字符串
#2021-04-29 21:38:11
a = time.strptime(a,"%Y-%m-%d %H:%M:%S") #将字符串时间转为 time对象 插入字符串格式化必须与字符串一一对应
#time.struct_time(tm_year=2021, tm_mon=4, tm_mday=29, tm_hour=21, tm_min=38, tm_sec=11, tm_wday=3, tm_yday=119, tm_isdst=-1)