//返回上传时间
static String timeString(Date createTime){
// static String timeString(){
//将传入的时间参数转成时间戳(秒)
long timeLong = createTime.getTime() / 1000;
// long timeLong = 1601088155;
//查看传入的时间戳与当前时间的差值(秒)
long timeDifference = ((new Date()).getTime() / 1000) - timeLong;
//一小时之内的返回值
if (timeDifference >= 0 && timeDifference < 60 * 60){
Long returnTime = timeDifference / 60;
if (returnTime == 0){
return "刚刚上传";
}
return returnTime + "分钟前上传";
}
//一小时之后到一天之间
if (timeDifference >= 60 * 60 && timeDifference < 60 * 60 * 24 ){
long returnTime = timeDifference / (60 * 60);
return returnTime + "小时前上传";
}
//一天到一周之间
if (timeDifference >= 60 * 60 * 24 && timeDifference < 60 * 60 * 24 * 7){
long returnTime = timeDifference / (60 * 60 * 24);
return returnTime + "天前上传";
}
//一周到一个月之间
if (timeDifference >= 60 * 60 * 24 * 7 && timeDifference < 60 * 60 * 24 * 30){
long returnTime = timeDifference / (60 * 60 * 24 * 7);
return returnTime + "周前上传";
}
//一个月到一年之间
if (timeDifference >= 60 * 60 * 24 * 30 && timeDifference < 60 * 60 * 24 * 365){
long returnTime = timeDifference / (60 * 60 * 24 * 30);
//规范写的是一个模糊值 12进行判断为11月前
if (returnTime == 12){
return "11月前上传";
}
return returnTime + "月前上传";
}
//一年即一年之后
if (timeDifference >= 60 * 60 * 24 * 365){
long returnTime = timeDifference / (60 * 60 * 24 * 365);
return returnTime + "年前上传";
}
return "";
}
Java返回数据上传过了多长时间
最新推荐文章于 2021-11-18 14:32:18 发布