活动时间判断
2015-06-03 15:52
204 查看
判断两个日期的间隔:
判断活动是1.倒计时;2.正在活动;3.活动到期
//计算两个日期的相隔天数 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"; }
相关文章推荐
- C++ 之STL priority_queue
- document.execCommand()的用法小记
- Eclipse Designer根据Activiti项目打包发布bar文件
- 使用bake安装dce quagga
- 【套题】Codeforces#304(div2)
- spring security之httpSecurity使用示例
- 如何让控制台不显示出来
- 并查集小结
- 几个复制表结构和表数据的方法
- boost的原子操作
- cocoapods安装前奏篇
- 关于activiti搭建的几条经验之一
- iOS开发——系统相册操作
- 破解Zephyr for JIRA on Atlassian Jira
- ORA-28001: the password has expired
- Facebook Paper使用的第三方库
- 冲刺第二阶段
- 微信支付调用JSAPI缺少参数:timeStamp
- java中的属性和字段
- [leetcode] Combination Sum III