python 获取今天 昨天 前天
#获取查询 参数
def getFidByDate(fid):
yesterDate = getDatetimeYesterday()
params="from="+yesterDate +"&to="+yesterDate +"&fid="+str(fid)
url=monitorUrl+params
u=urllib2.urlopen(url)
jsonData=json.loads(u.read().decode('utf-8'))
return jsonData["result"]
#得到今天日期
def getDatetimeToday():
t = date.today() #date类型
dt = datetime.strptime(str(t),'%Y-%m-%d') #date转str再转datetime
return dt
#得到昨天日期
def getDatetimeYesterday():
today = getDatetimeToday() # datetime类型当前日期
yesterday = today + timedelta(days=-1) # 减去一天
return str(yesterday).split()[0]
#得到前天日期
def getDatetimeQianTian():
today = getDatetimeToday() # datetime类型当前日期
qt = today + timedelta(days=-2) # 减去一天
return str(qt).split()[0]