import time # 获取结构化时间 print(time.localtime()) #time.struct_time(tm_year=2022, tm_mon=5, tm_mday=6, tm_hour=11, tm_min=34, tm_sec=35, tm_wday=4, tm_yday=126, tm_isdst=0) # 获取当前的时间戳 print(time.time()) #1651808178.187619 # 将结构化时间转换为时间戳 print(time.mktime(time.localtime())) #1651808372.0 # 将结构化时间转为字符串时间 print(time.strftime("%Y-%m-%d",time.localtime())) #2022-05-06 #将时间戳转换为结构化时间 print(time.localtime(time.time())) #time.struct_time(tm_year=2022, tm_mon=5, tm_mday=6, tm_hour=11, tm_min=43, tm_sec=25, tm_wday=4, tm_yday=126, tm_isdst=0) # 将时间戳转换为字符串时间(先将时间戳转换为结构化时间,再将结构化时间转换为字符串时间) print(time.strftime("%Y-%m-%d",time.localtime(time.time()))) #2022-05-06 # 将字符串转换为结构化时间 print(time.strptime('2008-03-12',"%Y-%m-%d")) #time.struct_time(tm_year=2008, tm_mon=3, tm_mday=12, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=72, tm_isdst=-1)