I have a small twist to the many,many questions already posted for this never ending problem.
How to find the number of minutes between two dates? The below code, does not take
the day in mind, so if end time is earlier than start time, the result is negative.
start = "2005/04/25 16:00:29";
end = "2005/04/26 13:21:15";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/dd/
mm H:mm:ss");
Date s = sdf.parse(start);
Date e = sdf.parse(end);
Calendar scal = java.util.GregorianCalenda
r.getInsta
nce();
scal.setTime(s);
Calendar ecal =java.util.GregorianCalend
ar.getInst
ance();
ecal.setTime(e);
long result = (e.getTime() - s.getTime())/60000;
result ===> -158 !
Start Free Trial