The following code might be helpful:
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.println("Enter two dates and time in the following format (yy/MM/dd HH:mm:ss) : ");
String dateStart = reader.nextLine();
String dateStop = reader.nextLine();
reader.close();
SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
java.util.Date d1 = null;
java.util.Date d2 = null;
try
{
d1 = format.parse(dateStart);
}
catch (java.text.ParseException e)
{
e.printStackTrace();
}
try
{
d2 = format.parse(dateStop);
}
catch (java.text.ParseException e)
{
e.printStackTrace();
}
long d = d2.getTime() - d1.getTime();
long dS = d / 1000 % 60;
long dM = d / (60 * 1000) % 60;
long dH = d / (60 * 60 * 1000);
long days=0;
if (dH>24)
{
days = dH/24;
dH = dH - (24*days);
}
System.out.println("The elapsed time is: "+days+" Days "+dH+" Hours "+dM+ " Minutes "+dS+" Seconds ");
}
}