判断两个日期的间隔:
//计算两个日期的相隔天数
public static int daysBetween(Date date1,Date date2){
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
long time1 = cal.getTimeInMillis();
cal.setTime(date2);
long time2 = cal.getTimeInMillis();
long between_days=(time2-time1)/(1000*3600*24);
return Integer.parseInt(String.valueOf(between_days));
}
判断活动是1.倒计时;2.正在活动;3.活动到期
public String rollIn() throws ParseException{
columns=articleBusi.getColumns();
//查询其他年份的招生简章
articles=articleBusi.getArticleByColumn(BaseConstant.ROLLIN);
if(articles!=null && articles.size()>0){
article=articles.get(0);//获取最近的文章
//判断活动时间
//开始时间是否大于当前日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(sdf.format(new Date()));
Date beginDate=new SimpleDateFormat("yyyy-MM-dd").parse(sdf.format(article.getRegBeginDate()));
Date endDate=new SimpleDateFormat("yyyy-MM-dd").parse(sdf.format(article.getRegEndDate()));
boolean flag1 = beginDate.before(date);
//结束时间小于当前日\
boolean flag2 = endDate.after(date);
boolean flag3=endDate.equals(date);
boolean flag4=beginDate.equals(date);
if(flag3 || flag4){
type=BaseConstant.ACTIVE_ONTIME;//正在报名
}else if(!flag1){//活动的开始时间在当前时间之后,倒计时
type=BaseConstant.ACTIVE_BEFOR_TIME;//倒计时
days=daysBetween(date,beginDate);
}else if(flag1&&flag2&&!flag3){
type=BaseConstant.ACTIVE_ONTIME;//正在报名
}else if(flag1&& !flag4){
type=BaseConstant.ACTIVE_OUTTIME;//活动过期
}
}else{
article=new Article();
}
return "rollIn";
}