将秒转换为天时分秒格式字符串(如是0天0时0分就显示秒)
/**
* 将秒转换为天时分秒格式字符串(如是0天0时0分就显示秒)
* @param seconds 秒数
* @return 返回天时分秒字符串
*/
private static String getStrOfSeconds(final long seconds) {
if(seconds < 0){
return "秒数必须大于0";
}
long one_day = 60 * 60 * 24;
long one_hour = 60 * 60;
long one_minute = 60;
long day,hour,minute,second = 0L;;
day = seconds / one_day;
hour = seconds % one_day / one_hour ;
minute = seconds % one_day % one_hour / one_minute;
second = seconds % one_day % one_hour % one_minute;
if(seconds < one_minute){
return seconds + "秒";
}else if(seconds >= one_minute && seconds < one_hour){
return minute + "分" + second + "秒";
}else if (seconds >= one_hour && seconds < one_day){
return hour + "时" + minute + "分" + second + "秒";
}else{
return day + "天" + hour + "时" + minute + "分" + second + "秒";
}
}