python datetime 时间戳转换

datetime时间与字符串相互转换

from datetime import datetime, timedelta

cur_datetime = datetime.now()
print(cur_datetime)
curdate = cur_datetime.strftime('%Y-%m-%d %H:%M:%S')
print(curdate)
tomorrow = cur_datetime + timedelta(days=1)
strftime  = tomorrow.strftime('%Y-%m-%d %H:%M:%S') #datetime 转string
print(strftime)
print(datetime.strptime(strftime, '%Y-%m-%d %H:%M:%S')) #字符串转datetime

你可能感兴趣的:(python datetime 时间戳转换)