/**
* 方法一 将毫秒数换算成x天x时x分x秒x毫秒
* time 毫秒
*/
public static String getSecondToDayHourMinutes(long ms) {
int ss =1000;
int mi = ss *60;
int hh = mi *60;
int dd = hh *24;
long day = ms / dd;
long hour = (ms - day * dd) / hh;
long minute = (ms - day * dd - hour * hh) / mi;
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
String strDay = day <10 ?"0" + day :"" + day;
String strHour = hour <10 ?"0" + hour :"" + hour;
String strMinute = minute <10 ?"0" + minute :"" + minute;
String strSecond = second <10 ?"0" + second :"" + second;
return strDay +":" + strHour +":" + strMinute +":" + strSecond;
}
/**
* 方法二 将毫秒数换算成x天x时x分x秒x毫秒
* time 毫秒
*/
public static String getLongTimeToDayHourMinutes(long ms) {
int ss =1000;
int mi = ss *60;
int hh = mi *60;
int dd = hh *24;
long day = ms / dd;
long hour = (ms - day * dd) / hh;
long minute = (ms - day * dd - hour * hh) / mi;
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
StringBuffer sb =new StringBuffer();
String dayText ="";
String hourText ="";
String minutesText ="";
String secondText ="";
if (day >0) {
sb.append(day <10 ?"0" + day :"" + day);
sb.append("天");
}
if (day >0) {
sb.append(" ");
}
if (day >0 || hour >0) {
sb.append(hour <10 ?"0" + hour :"" + hour);
sb.append(":");
}
if (minute >0 || day >0 || hour >0) {
sb.append(minute <10 ?"0" + minute :"" + minute);
sb.append(":");
}
sb.append(second <10 ?"0" + second :"" + second);
sb.append("");
return sb.toString();
}
网友评论