把毫秒转换成日期、天数

把一个毫秒转换成日期

private String timeToString(Long millisecond){
String str = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp ts = new Timestamp(millisecond);
str = sdf.format(ts);
return str;
}


计算X毫秒相当于几天

private String periodToString(Long millisecond){
String str = "";
long day = millisecond / 86400000;
long hour = (millisecond % 86400000) / 3600000 ;
long minute = (millisecond % 86400000 % 3600000) / 60000;
if(day > 0){
str = String.valueOf(day) + "天";
}
if(hour > 0){
str += String.valueOf(hour) + "小时";
}
if(minute > 0){
str += String.valueOf(minute) + "分钟";
}
return str;
}

你可能感兴趣的:(把毫秒转换成日期、天数)