您的位置:首页 > 其它

将秒数转换成天具体的天时分秒

2016-07-11 11:04 246 查看
/**
* 将秒数转换成天具体的天时分秒
* 比如172800S转换成2天0时0分0秒
* @param second
* @return
*/
public String formatSecond(Object second){
String  timeStr = "0秒";
if(second!=null){
Double s=(Double) second;
String format;
Object[] array;
Integer days = (int)(s /(60 * 60 * 24));
Integer hours =(int)(s/(60*60) - days * 24);
Integer minutes = (int)(s/60 - hours*60 - days * 24 * 60);
Integer seconds = (int)(s-minutes*60-hours*60*60 - days * 24 * 60 * 60);
if(days>0){
format="%1$,d天%2$,d时%3$,d分%4$,d秒";
array=new Object[]{days,hours,minutes,seconds};
} else if(hours>0){
format="%1$,d时%2$,d分%3$,d秒";
array=new Object[]{hours,minutes,seconds};
}else if(minutes>0){
format="%1$,d分%2$,d秒";
array=new Object[]{minutes,seconds};
}else{
format="%1$,d秒";
array=new Object[]{seconds};
}
timeStr = String.format(format, array);
}
return timeStr ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息