I am trying to compute the difference in time between two date/times. This is what I have imported:
import java.util.concurrent.TimeUnit;
import java.text.*;
import java.util.*;
And this is my code:
SimpleDateFormat format= new SimpleDateFormat("yy/MM/dd HH:mm:ss");
String dateStart = "11/03/14 19:29:58";
String dateStop = "11/05/14 08:03:13";
Date d1=null;
Date d2=null;
try{
d1 = format.parse(dateStart);
d2=format.parse(dateStop);
}
catch(ParseException e)
{
e.printStackTrace();
}
long diff = d2.getTime()-d1.getTime();
long seconds = TimeUnit.MILLISECONDS.toSeconds(diff);
long minutes=TimeUnit.MILLISECONDS.toMinutes(diff);
System.out.println(minutes);
This, I think, should work fine, but instead of the correct answer I get "87153". What is the source of error and how can I correct it?