@ruoli
2018-10-17T18:16:33.000000Z
字数 578
阅读 951
Java基础
/**
*
* @param 要转换的毫秒数
* @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
* @author fy.zhang
*/
public String formatDuring(long mss){
long days = mss / (1000*60*60*24);
long hours = (mss % (1000*60*60*24)) / (1000*60*60);
long minutes = (mss % (1000*60*60)) / (1000*60);
long seconds = (mss % (1000*60)) /1000;
return (days>0?(days+"天 "):"")
+(hours>0?(hours+"小时"):"")
+(minutes>0?(minutes+"分"):"")
+(seconds>0?(seconds+"秒"):"");
}
public String formatDuring(Date begin, Date end) {
return formatDuring(end.getTime() - begin.getTime());
}
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");