WebLinuxStudy

导航

 

import time

year = 2020
month = 1
day = 20

dateStr = "{}-{}-{}".format(year, month, day)
print(dateStr)

# 时间字符串解析为时间元组
timeArray = time.strptime(dateStr, "%Y-%m-%d")
# 将时间元组转换为时间戳:
timeStamp = int(time.mktime(timeArray))

print(timeStamp)

# 格式化时间戳为时间元组
timeArray = time.localtime(timeStamp)
# 将时间元组转换为时间字符串
timeStr = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)

print(timeStr)

 

posted on 2021-02-07 15:28  WebLinuxStudy  阅读(885)  评论(0编辑  收藏  举报