可能重复:
Compare dates in Java
我需要比较两个日期date1和date2,条件是:
对于使用if(date2.after(date1))
的第一个条件但是对于第二个我不确定......
我正在使用Calendar calendar = Calendar.getInstance(); calendar.setTime(fecha1); calendar.add(Calendar.MONTH,+ 14); 日期nuevaFecha1 =(日期)calendar.getTime();
一些想法如何验证这个
答案 0 :(得分:0)
试试这个
Calendar calendar1 = Calendar.getInstance();
calendar1.set(Calendar.YEAR, year);
calendar1.set(Calendar.MONTH, month );
calendar1.set(Calendar.DAY_OF_MONTH, day);
Calendar calendar2 = Calendar.getInstance();
calendar2.set(Calendar.YEAR, year);
calendar2.set(Calendar.MONTH, month );
calendar2.set(Calendar.DAY_OF_MONTH, day);
long mills1 = calendar1.getTimeInMillis();
long mills2 = calendar2.getTimeInMillis();
if(mills1 > mills2){
}else{
}