def date():
import time
import random
a1=(2020,1,1,0,0,0,0,0,0)
a2=(2020,12,31,23,59,59,0,0,0)
start=time.mktime(a1)
end=time.mktime(a2)
for i in range(1):
t=random.randint(start,end)
date_touple=time.localtime(t)
date=time.strftime("%Y-%m-%d",date_touple)
return date
本方法通过时间戳实现
def getDate():
import random
date = ['/5/10','/1/10','/2/7','/9/8']
time = str(random.choice(date) )
return time
随机读取列表中的日期