1.使用after或before
注意是import java.util.Date;
1)日期相同的时候
Date date = new Date(2016,9,6); Date date2 = new Date(2016,9,6); System.out.println(date.before(date2));//false System.out.println(date.after(date2));//false
2)日期1小于日期2
Date date = new Date(2016,9,5); Date date2 = new Date(2016,9,6); System.out.println(date.before(date2));//true System.out.println(date.after(date2));//false
3)日期1大于日期2
Date date = new Date(2016,9,7); Date date2 = new Date(2016,9,6); System.out.println(date.before(date2));//false System.out.println(date.after(date2));//true