Hi,
I got the following code :
String str1 = "01/17/2001";
String str2 = "2001-01-17";
SimpleDateFormat df1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = null, date2 = null;
try {
date1 = df1.parse(str1);
} catch (java.text.ParseException e) {
// handle invalid date
}
try {
date2 = df2.parse(str2);
} catch (java.text.ParseException e) {
// handle invalid date
}
How to compare if the different of the 2 Date objects is 2 months or 2 years ? Like
if((date1 - date2) == 2 months)
System.out.println("2 months different");
Pls help.......
I got the following code :
String str1 = "01/17/2001";
String str2 = "2001-01-17";
SimpleDateFormat df1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = null, date2 = null;
try {
date1 = df1.parse(str1);
} catch (java.text.ParseException e) {
// handle invalid date
}
try {
date2 = df2.parse(str2);
} catch (java.text.ParseException e) {
// handle invalid date
}
How to compare if the different of the 2 Date objects is 2 months or 2 years ? Like
if((date1 - date2) == 2 months)
System.out.println("2 months different");
Pls help.......