1. 显示当前格式化日期时间
import time
# 显示当前格式化日期时间
def now_time():
now = int(time.time()) #获取当时时间戳
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
2. 将指定时间戳转换为日期时间
# 将指定时间戳转换为日期时间
def timestamp_to_datetime(mytime):
timeArray = time.localtime(mytime)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
3. 将指定日期时间转换为时间戳
# 将指定日期时间转换为时间戳
def datetime_to_timestamp(mytime):
timeArray = time.strptime(mytime, "%Y-%m-%d %H:%M:%S")
timeStamp = int(time.mktime(timeArray))
return timeStamp
原文地址:https://blog.csdn.net/tsfy2003/article/details/106206186