you can simply compare both YEAR and WEEK_OF_YEAR....
解决方案 »
- 项目启动时报错:java.lang.ClassNotFoundException: org.apache.log4j.LogManager
- 一个java自动打开文件的问题
- 字符串转换为日期格式
- java操作cmd的命令
- 大哥们给小弟个答案啊!为什么不能运行
- 没完成的程序,不会写了实在,大家谁能帮我一下,初学者
- 能否判断两个多边形是否intersect
- 正则表达式提取字符串求解
- JSplitPane的定位问题
- 能把一个类作为整体地读写进文件吗?
- 请问一下为什么Class.forName()可以不用返回给一个class对象,而直接调用呢?
- 请问有关windowsUtilities class 的用法!谢谢
Calendar calNow = Calendar.getInstance();
cal.setTime(dateInst);
int subYear = calNow.get(Calendar.YEAR) - cal.get(Calendar.YEAR);
if (0 == subYear) { if (0 = (cal.get(calNow.get(Calendar.WEEK_OF_YEAR) - cal.get(cal.get(Calendar.WEEK_OF_YEAR)))
return true;
}
else if (1 == subYear && (1 == calNow.get(Calendar.WEEK_OF_YEAR) && cal.get(Calendar.WEEK_OF_YEAR) == cal.getMaximum(Calendar.WEEK_OF_YEAR))) {
if (1 != calNow.getFirstDayOfWeek())
return true;
}
else if (-1 == subYear && (1 == cal.get(Calendar.WEEK_OF_YEAR) && calNow.get(Calendar.WEEK_OF_YEAR) == calNow.getMaximum(Calendar.WEEK_OF_YEAR))) {
if (1 != cal.getFirstDayOfWeek())
return true;
}
return false;//注意时区问题,美国以SUNDAY作为1周的第一天,而中国是MONDAY
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
if (0 == subYear) {
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
return true;
}
else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {
// 如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
return true;
}
else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
return true;
}
return false;
}
//注意时区问题,美国以SUNDAY作为1周的第一天,而中国是MONDAY