import time
#获取此时的时间戳
time_timestamp = time.time()
print(time_timestamp) #1609656974.8415737
#将时间戳转换为时间元组
print(time.gmtime(time_timestamp))
#获取此时的时间元组
time_tuple = time.localtime()
print(time_tuple) #time.struct_time(tm_year=2021, tm_mon=1, tm_mday=3, tm_hour=14, tm_min=56, tm_sec=14, tm_wday=6, tm_yday=3, tm_isdst=0)
#将时间元组转为时间戳
print(time.mktime(time_tuple))
#将时间元组转换为可读时间字符串
print(time.strftime('%Y-%m-%d %H:%M:%S',time_tuple))
time_str = time.strftime('%Y-%m-%d %H:%M:%S',time_tuple)
#将时间可读字符串转换为时间元组
print(time.strptime(time_str,'%Y-%m-%d %H:%M:%S'))
万水千山总是情,点个关注行不行。100多篇博客总有一篇适合您。