Because this is not how you get the duration. Change your code to this:
package com.sandbox; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Sandbox { public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); try { Date start = sdf.parse("00:44:16"); Date end = sdf.parse("04:02:39"); long duration = end.getTime() - start.getTime(); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(duration); System.out.println(new SimpleDateFormat("yyyy MM dd HH:mm:ss").format(cal.getTime())); } catch (ParseException e) { e.printStackTrace(); } } }
You will see that it prints 1969 12 31 19:18:23 . This date is not a duration. Since you skip the date components when you print your answer, it seems to print a duration, but it really is.
To be honest, I do not know how to do this in java. I just use the JodaTime library. There, a class called Duration makes it easier. Here is a SO question that shows how to use it to print results in any way: "pretty print" duration in java
source share