本文记录 Python time 模块时间与秒数转换的方法。...转换方法
加载 time 模块
import time
获取当前秒数
current = time.time()
current = 1636181668.299232
秒数为正经的 float...type(time.time())
秒数转换为时间
lt = time.localtime(current)
print(lt)
to_time = time.strftime...tm_mday=6, tm_hour=14, tm_min=54, tm_sec=28, tm_wday=5, tm_yday=310, tm_isdst=0)
2021-11-06 14:54:28
使用时间创建时间对象...(2021, 11, 6, 14, 54, 28)
将时间对象转换为秒数
# 需要先转换为 struct_time
tt = dt.timetuple()
tt = time.struct_time