时间显示
System.out.println(getTimeStr(1));
System.out.println(getTimeStr(10));
System.out.println(getTimeStr(100));
System.out.println(getTimeStr(1000));
System.out.println(getTimeStr(10000));
输出结果
00:00:01
00:00:10
00:01:40
00:16:40
02:46:40
下面代码不解释了
public static String getTimeStr(int time){
StringBuffer str=new StringBuffer();
int hour=time/3600;
if (hour>9) {
str.append(hour);
}else{
str.append("0");
str.append(hour);
}
str.append(":");
int minute=(time%3600)/60;
if (minute>9) {
str.append(minute);
}else{
str.append("0");
str.append(minute);
}
str.append(":");
int second=time%60;
if (second>9) {
str.append(second);
}else{
str.append("0");
str.append(second);
}
return str.toString();
}