java 把秒 转换为时间格式

`

  //根据秒获取时间格式   结果为 :  long i =  2591881;   29天23小时58分钟1秒
public static String formatDateTime(long mss) {
	String DateTimes = null;
	long days = mss / ( 60 * 60 * 24);
	long hours = (mss % ( 60 * 60 * 24)) / (60 * 60);
	long minutes = (mss % ( 60 * 60)) /60;
	long seconds = mss % 60;
	if(days>0){
		DateTimes= days + "天" + hours + "小时" + minutes + "分钟"
				+ seconds + "秒";
	}else if(hours>0){
		DateTimes=hours + "小时" + minutes + "分钟"
				+ seconds + "秒";
	}else if(minutes>0){
		DateTimes=minutes + "分钟"
				+ seconds + "秒";
	}else{
		DateTimes=seconds + "秒";
	}

	return DateTimes;
}
  `
posted @ 2021-01-11 11:52  优优鱼  阅读(3738)  评论(0编辑  收藏  举报