话不多少直接贴代码
private String coverToShowTime(Date updateTime) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
long time = (System.currentTimeMillis() - updateTime.getTime()) / 1000;
//小于60 秒显示刚刚
String result = sf.format(updateTime);
long temp = 0;
if (time < 60) {
result = "刚刚";
//小于60分钟直接显示几分钟前
}else if( (temp = time/60) <60){
result = temp + "分钟前";
//小于24小时直接显示几小时前
}else if((temp = time/(60*60)) <24){
result = temp + "小时前";
//小于7天显示几天前
}else if((temp = time/(86400)) <7){
result = temp + "天前";
////大于7天小于14天显示1周前
}else if((temp = time/(86400*7)) <2){
result = temp + "周前";
}
return result;
}
效果