python3 time时间戳转换

import time

格式化时间转时间戳

ctime = time.strftime("%Y-%m-%d %H:%M:%S")

先转成struct_time

ctime = time.strptime(ctime, "%Y-%m-%d %H:%M:%S")

再转成时间戳

ctime = time.mktime(ctime)

时间戳转格式化时间

stamp = time.time()

先转成struct_time

stamp = time.localtime(stamp)

再转成格式化时间

ctime = time.strftime("%Y-%m-%d %H:%M:%S", stamp)
原文地址:https://www.cnblogs.com/cooolr/p/time.html