Convert time in seconds to a string in 00:00:00
class Main{
public static String pad(int num) {
String res = null;
if(num < 10)
res = "0" + num;
else
res = "" + num;
return res;
}
static public String getStringTime(int time) {
String res = null;
int hour, min, sec;
if (time > 0) {
hour = time / 3600;
time %= 3600;
min = time / 60;
sec = time % 60;
res = pad(hour) +":" + pad(min) + ":" + pad(sec) + ":";
}
// TODO Auto-generated method stub
return res;
}
}
Related examples in the same category