private static final DateFormat
FORMATOR_MD_CN =
new SimpleDateFormat(
"MM-dd HH:mm");
private long updateTimestamp;
// 最新修改时间 number
private long nowTimestamp;
//
private static final long m =
60 *
1000L;
// 分
private static final long hour =
3600 *
1000L;
// 小时
public String getDiffTimes() {
if (
nowTimestamp ==
0 ||
updateTimestamp ==
0)
return "";
long cha = Math.
abs(
nowTimestamp -
updateTimestamp);
long hours = cha /
hour;
if (hours <
1) {
if (cha /
m <=
0) {
return "刚刚";
}
return cha /
m +
"分钟前";
}
if (hours <
24) {
return cha /
hour +
"小时前";
}
return FORMATOR_MD_CN.format(
new Date(
updateTimestamp));
}
转载请注明原文地址: https://www.6miu.com/read-63744.html