python3 time时间戳转换

lr 于 2020-11-03 发布
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)