Skip to content

Instantly share code, notes, and snippets.

@dzwillpower
Created July 18, 2012 07:42
Show Gist options
  • Save dzwillpower/3134866 to your computer and use it in GitHub Desktop.
Save dzwillpower/3134866 to your computer and use it in GitHub Desktop.
将毫秒转换为 00:00:00 格式的的字符串 String
/**
* 将毫秒时间转换成时分秒
* @param totalTime
* @return
*/
public String formatTime(int totalTime){
int hour = 0;
int minute = 0;
int second = 0;
second = totalTime / 1000;
Log.i(TAG, "second = " + second);
if (totalTime <= 1000 && totalTime > 0) {
second = 1;
}
if (second > 60) {
minute = second / 60;
second = second % 60;
}
if (minute > 60) {
hour = minute / 60;
minute = minute % 60;
}
// 转换时分秒 00:00:00
String duration = (hour >= 10 ? hour : "0" + hour)+ ":" +(minute >= 10 ? minute : "0" + minute)+ ":" +(second >= 10 ? second : "0" + second);
return duration;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment