This is my code,
e.g. 2year, 2 month, 1 week 2 days, 1 hour, 2 minutes , 35 seconds.
String stdate ="01/01/2014 09:30:30";
String endate ="09/11/2015 11:30:30";
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
Date d1 = new Date();
Date d2 = new Date();
long year =(1000*60*60*24*365l);
long month =(1000*60*60*24*30l);
long weeks =(1000*60*60*24*7l);
long days =(1000*60*60*24l);
try{
d1 = df.parse(stdate);
d2 = df.parse(endate);
long diff = d2.getTime()-d1.getTime();
long diffYear = diff/(1000*60*60*24*365l);
long diffMonth = (diff-(diffYear*year))/month;
long diffWeeks = ((diff%month))/weeks;
long diffDays = ((diff%weeks))/days;
System.out.println(diffYear+" years ");
System.out.println(diffMonth+" months ");
System.out.println(diffWeeks+" week ");
System.out.println(diffDays+" days "); // wrong output,
}catch(Exception e){
}
o/p:
1 years
10 months
2 week
5 days
I do not want to use joda time. it should be in java.util.*;
Please answer, thanks in advance.