2019-05-20转换 2019年-05月-20日

 

# 2019-05-25 11:20:34
updatetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
import datetime
import time


today=datetime.date.today()
oneday=datetime.timedelta(days=1)
yesterday=today-oneday

print(yesterday) # 2019-05-20
print(time.strftime('%Y{y}-%m{m}-%d{d}').format(y='年', m='月', d='日'))  # 2019年-05月-21日
print((datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y{y}-%m{m}-%d{d}').format(y='年', m='月', d='日'))   # 2019年-05月-20日


# --------

t = '2019-05-21 15:16:01'
timeArray = time.strptime(t,"%Y-%m-%d %H:%M:%S")
timeStamp = int(time.mktime(timeArray))
print(timeStamp)   # 1558422961


# --------

time_stamp = 1558422961
time_array = time.localtime(time_stamp)
str_time = time.strftime("%Y-%m-%d %H:%M:%S")
print(str_time)

 

你可能感兴趣的:(py)