My time difference is showing an incorrect output, I'm trying to calculate the time difference between startTime and endTime.
Date time1, time2;
long difference;
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
public Time(String startTime, String endTime)
{
this.startTime = startTime;
this.endTime = endTime;
time1 = new Time("16:30", "18:00"); //example
try
{
time1 = df.parse(startTime);
time2 = df.parse(endTime);
}
catch(Exception e) {
System.out.println("invalid time");
}
}
public String getDifference()
{
difference = (time2.getTime() - time1.getTime());
return df.format(difference); //output = 02:30, should be 01:30
}
I know that Joda-Time could make this easier, but I'm supposed not to use any other library.