把分钟转换为时分秒:
public static String minConvertHourMinSecond(Integer min) {
String result = "";
if (min != null) {
Integer m = min;
String format;
Object[] array;
Integer days = m / (60 * 24);
Integer hours = m / (60) - days * 24;
Integer minutes;
Integer second;
if (days > 0) {
hours += days * 24;
minutes = m - hours * 60;
second = ( m - minutes - hours * 60) / 60;
}else{
minutes = m - hours * 60 - days * 24 * 60;
second = (m - minutes - hours * 60) / 60;
}
String hoursstr = null;
String minutesstr = null;
String secondstr = null;
if(hours < 10){
hoursstr = "0"+hours;
}else {
hoursstr = hours + "";
}
if(minutes < 10){
minutesstr="0"+minutes;
}else {
minutesstr = minutes + "";
}
if(second < 10){
secondstr="0"+second;
}else {
secondstr = second + "";
}
format = "%1$s:%2$s:%3$s";
array = new Object[]{hoursstr, minutesstr,secondstr};
result = String.format(format, array);
}
return result;
}
下面的方法是分钟转换为天时分:
public static String minConvertDayHourMin(Double min) {
String result = "0分";
if (min != null) {
Double m = (Double) min;
String format;
Object[] array;
Integer days = (int) (m / (60 * 24));
Integer hours = (int) (m / (60) - days * 24);
Integer minutes = (int) (m - hours * 60 - days * 24 * 60);
if (days > 0) {
format = "%1$,d天%2$,d时%3$,d分";
array = new Object[]{days, hours, minutes};
} else if (hours > 0) {
format = "%1$,d时%2$,d分";
array = new Object[]{hours, minutes};
} else {
format = "%1$,d分";
array = new Object[]{minutes};
}
result = String.format(format, array);
}
return result;
}