#coding:UTF-8 import time import random import re # 根据时间返回,返回随机年月日时间 def getRandomDate(sYear, sMonth, sDay, eYear, eMonth, eDay): a1=(sYear,sMonth,sDay,0,0,0,0,0,0) a2=(eYear,eMonth,eDay,23,59,59,0,0,0) start=time.mktime(a1) end=time.mktime(a2) t=random.randint(start,end) date_touple=time.localtime(t) date=time.strftime("%Y/%m/%d",date_touple) return date
调用:getRandomDate(2010,1,1,2019,1,1)