在JSP页面中,我有四个样本日期,如01-dec,15-dec,30-dec和15-jan。我需要检查上面的日期和当前日期的差异是否为15。
这是我的尝试:
Calendar calendar = Calendar.getInstance();
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
Calendar calendar3 = Calendar.getInstance();
Calendar calendar4 = Calendar.getInstance();
calendar1.set(2011, 11, 02);
calendar2.set(2011, 06, 02);
calendar3.set(2011, 09, 07);
calendar4.set(2011, 06, 05);
long milliseconds1 = calendar1.getTimeInMillis();
long milliseconds2 = calendar.getTimeInMillis();
long diff = milliseconds2 - milliseconds1;
long diffDays = diff / (24 * 60 * 60 * 1000);
if (diffDays <= 15) {
System.out.println("Fifteen");
} else {
System.out.println("No Fifteen");
}
我要检查所有四种情况的条件是否差异为15。将这些日历实例放在地图或列表中。我不知道怎么做。