This question already has an answer here:
- How to format a duration in java? (e.g format H:MM:SS) 17 answers
I have a problem figuring out how to calculate the elapsed time between two timestamps (hours, minutes, seconds). This is the result:
String starttime = beginElement.getTimestamp();
String endtime = element.getTimestamp();
I/Start time: 1496258892612
I/End time: 1496258928999
long diffTime = Long.parseLong(endtime) - Long.parseLong(starttime);
I/Diff time: 36387
String elapsedtime = new SimpleDateFormat("hh:mm:ss").format(Long.parseLong(String.valueOf(diffTime)));
I/Elapsed time: 01:00:36
In fact, the elapsed time is just 36 seconds. It's always one hour less than the result.
How do I fix this strange issue?