/**
*
* @param millis 要转化的毫秒数。
*
* @param isWhole 是否强制全部显示小时/分。
*
* @param isFormat 时间数字是否要格式化,如果true:少位数前面补全;如果false:少位数前面不补全。
*
* @return 返回时间字符串:小时/分/秒/毫秒的格式(如:24903600 --> 06小时55分钟)。
*/
public static String millisToStringShort(long millis, boolean isWhole,
boolean isFormat) {
String h = "";
String m = "";
if (isWhole) {
h = isFormat ? "00小时" : "0小时";
m = isFormat ? "00分钟" : "0分钟";
}
long temp = millis;
long hper = 60 * 60 * 1000;
long mper = 60 * 1000;
long sper = 1000;
if (temp / hper > 0) {
if (isFormat) {
h = temp / hper < 10 ? "0" + temp / hper : temp / hper + "";
} else {
h = temp / hper + "";
}
h += "小时";
}
temp = temp % hper;
if (temp / mper > 0) {
if (isFormat) {
m = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";
} else {
m = temp / mper + "";
}
m += "分钟";
}
return h + m;
}
/**
* 把毫秒转为 分:秒
*/
public static String millisToStringShort(long millis, boolean isWhole,
boolean isFormat) {
String h = "";
String m = "";
if (isWhole) {
h = isFormat ? "00小时" : "0小时";
m = isFormat ? "00分钟" : "0分钟";
}
long temp = millis;
long mper = 60 * 1000;
long sper = 1000;
if (temp / mper > 0) {
if (isFormat) {
h = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";
} else {
h = temp / mper + "";
}
h += ":";
}
temp = temp % mper;
if (temp / sper > 0) {
if (isFormat) {
m = temp / sper < 10 ? "0" + temp / sper : temp / sper + "";
} else {
m = temp / sper + "";
}
m += "";
}
return h + m;
}