1、时间格式:time
import time,random,datetime
dat=time.strftime("%Y%m%d%H%M%S",time.localtime())
dat2 = time.strftime("%Y-%m-%d",time.localtime())
print (dat,dat2)
>>>
20191219195354 2019-12-19
# 今天日期
today = datetime.date.today()
# 昨天时间
yesterday = today - datetime.timedelta(days=1)
# 明天时间
tomorrow = today + datetime.timedelta(days=1)
#后天时间
acquire = today + datetime.timedelta(days=2)
print(today,tomorrow,acquire)
>>>
2019-12-19 2019-12-20 2019-12-21
2.datetime
import string,random,time,datetime
def tampe(days1):
dat1 = str(datetime.timedelta(days=days1) + datetime.date.today())
ti1 = time.strptime(dat1, "%Y-%m-%d")
ti2 = int(time.mktime(ti1)) * 1000
return ti2
3.今天明天昨天
def days(no1):
import time
#当前时间以2022-02-15形式展示
todayday= time.strftime("%Y-%m-%d", time.localtime())
#当前时间以十位的时间戳1644854400形式展示
todaytamp = int(time.mktime(time.strptime(todayday, "%Y-%m-%d")))
if no1==1:
daytamp=todaytamp
#+1天,也就是明天
elif no1==2:
daytamp=todaytamp+86400000
#-1天,也就是昨天
elif no1 == 3:
daytamp = todaytamp - 86400000
else:
daytamp=todaytamp
print(daytamp)
return daytamp
if __name__=='__main__':
days(1)
days(2)
days(3)