ITPub博客

首页 > 应用开发 > Java > 日期操作相关

日期操作相关

原创 Java 作者:zenzuguo 时间:2006-10-27 17:13:47 0 删除 编辑
public boolean checkCourseTimes(List schedules, Long schoolId){
boolean flag=false;
if(schedules==null)return false;
schedules.remove(null);
Collections.sort(schedules, new Comparator() {
public int compare(Object a, Object b) {
Schedule cs1 = (Schedule) a;
Schedule cs2 = (Schedule) b;
if(cs1==null||cs2==null)return 0;
Date cs1date=cs1.getStartTime();
Date cs2date=cs2.getStartTime();
int temp=cs1date.compareTo(cs2date);
return temp;
}
});
//firt day
Schedule firtsch=(Schedule)schedules.get(0);
Date firstday=firtsch.getStartTime();
Calendar ca=Calendar.getInstance();
ca.setTime(firstday);
int step = ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, -step);
Date weekFirstDay = ca.getTime();
//last day
Schedule lastsch=(Schedule)schedules.get(0);
Date lastday=firtsch.getStartTime();
ca.setTime(lastday);
step = 7 - ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, step);
Date weekLastDay = ca.getTime();
long subs = weekLastDay.getTime()-weekFirstDay.getTime();
long betweenDays = (long)(subs / (1000 * 60 * 60 *24) + 0.5);
int weeks=(int)(betweenDays / 7+0.5);
return flag;
}[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/106285/viewspace-874024/,如需转载,请注明出处,否则将追究法律责任。

下一篇: hibernate性能问题
请登录后发表评论 登录
全部评论

注册时间:2012-12-30

  • 博文量
    84
  • 访问量
    829565