Date comparison in java:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Date date1 = sdf.parse("2009-12-31");
Date date2 = sdf.parse("2009-12-31");
System.out.println(sdf.format(date1));
System.out.println(sdf.format(date2));
if(date1.after(date2)){
System.out.println("Date1 is after Date2");
}
if(date1.before(date2)){
System.out.println("Date1 is before Date2");
}
if(date1.equals(date2)){
System.out.println("Date1 is equal Date2");
}
No comments:
Post a Comment