I have 2 times in calendar.
Calendar orarioP1 = new GregorianCalendar(2014, 3, 28, 8, 30, 00);
Calendar orarioA1 = new GregorianCalendar(2014, 3, 28, 12, 35, 06);
I implemented this function for get the time difference but it return me +1hour difference.
I need to return the correct difference 4:05:06
but now it return me 5:05:06
. Can anyone help me?
public String getTimeDiff() {
SimpleDateFormat sdf = new SimpleDateFormat("h:mm:ss");
long milliSec1 = orarioP1.getTimeInMillis();
long milliSec2 = orarioA1.getTimeInMillis();
long timeDifInMilliSec;
if(milliSec1 >= milliSec2) {
timeDifInMilliSec = milliSec1 - milliSec2;
} else {
timeDifInMilliSec = milliSec2 - milliSec1;
}
long timeDifSeconds = timeDifInMilliSec / 1000;
long timeDifMinutes = timeDifInMilliSec / (60 * 1000);
long timeDifHours = timeDifInMilliSec / (60 * 60 * 1000);
long timeDifDays = timeDifInMilliSec / (24 * 60 * 60 * 1000);
Date date = new Date(timeDifSeconds);
String difference = sdf.format(date);
return difference;
}