/**
* 得到几天前的时间
* @param d
* @param day
* @return
*/
public static Date getDateBefore(Date d,int day){
Calendar now =Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE,now.get(Calendar.DATE)-day);
return now.getTime();
}
/**
* 得到几天后的时间
* @param d
* @param day
* @return
*/
public static Date getDateAfter(Date d,int day){
Calendar now =Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE,now.get(Calendar.DATE)+day);
return now.getTime();
}
/**
*获取今天的时间的凌晨 到 23点
*
*/
private void initTime(){
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
this.startTime=sdf.format(cal.getTime())+" 00:00:00";
this.endTime=sdf.format(cal.getTime())+" 23:59:59";
}
//判断是不是昨天.同一天,前天
//判断是不是今天
private boolean isToday(Date time){
try {
Date nowTime=new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String todayStr = format.format(nowTime);
Date today = format.parse(todayStr);
long starttime=today.getTime();
long endtime=today.getTime()+86400000;
if(starttime<=time.getTime() && time.getTime()<=endtime){
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}