In my code, I am generating timestamps value that is long millisecond .I want to convert this to HH:mm:ss(600000 to 00:10:00),I want disply difference in hh:mm:ss format
String strstart = "8:30:00";
String strend = "8:40:00";
SimpleDateFormat sdf1 = new SimpleDateFormat("hh:mm:ss");
try {
Date date1 = sdf1.parse(strstart);
Date date2 = sdf1.parse(strend);
long durationInMillis = date2.getTime() - date1.getTime();
System.out.println("durationInMillis---->" + durationInMillis);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I use bellow code and the output is 0:10:0
like this but i want the output like 00:10:00
int seconds = (int) (durationInMillis / 1000) % 60 ;
int minutes = (int) ((durationInMillis / (1000*60)) % 60);
int hours = (int) ((durationInMillis / (1000*60*60)) % 24);
System.out.println(hours+":"+minutes+":"+seconds);