Actually i am stuck into minor issue but not getting any proper solution. I have two dates in same format now i want difference between but the format would be (Year - Month - Days - Hours - Mints - Sec) and here is my code
public static void getDifferent(Date startDate, Date endDate) {
//milliseconds
long different = endDate.getTime() - startDate.getTime();
System.out.println("startDate : " + startDate);
System.out.println("endDate : " + endDate);
System.out.println("different : " + different);
long secondsInMilli = 1000;
long minutesInMilli = secondsInMilli * 60;
long hoursInMilli = minutesInMilli * 60;
long daysInMilli = hoursInMilli * 24;
long monthInMili = daysInMilli * 30;
long elapsedMonths = different / monthInMili;
long elapsedDays = different / daysInMilli;
different = different % daysInMilli;
long elapsedHours = different / hoursInMilli;
different = different % hoursInMilli;
long elapsedMinutes = different / minutesInMilli;
different = different % minutesInMilli;
long elapsedSeconds = different / secondsInMilli;
Log.d("Difference", "startDate: " + startDate.toString() + " endDate: " + endDate + " Months : " + elapsedMonths + " Days :" + elapsedDays + " Hours :" +
elapsedHours + " Mint :" + elapsedMinutes + " Seconds :" + elapsedSeconds);
}
This is code is not perfect due to this line
long monthInMili = daysInMilli * 30;
So please guide me. I am not getting proper solution from long time.