將秒數 [整數型] 匹配成 xx時 xx分xx秒
/**
* 將秒數 匹配成 xx時 xx分xx秒
*
* @param time
* @return
*/
public static String secondUpMatch(int time) {
int hour = 0;
int minute = 0;
int second = 0;
if (time <= 0) {
return "";
}
// 不足一分鐘 --> xx秒
if (time < 60) {
return time + "秒";
}
minute = time / 60;
// 不足一小時 --> xx分xx秒
if (minute < 60) {
second = time % 60;
return minute + "分" + (second > 0 ? second + "秒" : "");
}
hour = minute / 60;
minute = minute % 60;
second = time - hour * 3600 - minute * 60;
return hour + "時" + (minute > 0 ? minute + "分" : "") + (second > 0 ? second + "秒" : "");
}