time库
import time
1)time库的time方法
# 当前 秒数时间
import time
time.time()
2)time库的localtime方法
作用:秒数时间--->struct_time对象
参数:秒数,默认当前秒数时间
返回:struct_time对象
3)time库的strftime方法
作用:struct_time对象---->字符串
参数1:指定 返回的字符串 的格式
参数2:待转换的 struct_time对象
time.strftime(\'%Y-%m-%d\', time.localtime())
time库 总结:
关键词: struct_time对象
秒数--------.localtime()----------->struct_time对象----------.strftime()---------->字符串
import time
# 当前秒数时间
seconds = time.time()
# 秒数时间 转换为 struct_time对象
structtime = time.localtime(seconds)
# struct_time对象 转换为 字符串(日期时间)
strf = \'%Y-%m-%d %H:%M:%S\'
strtime = time.strftime(strf, structtime) # 2020-11-20 15:18:54