/**
* 时间戳转为多久之前
* @param time 毫秒
* @return
*/
public static String getTimeAgo(long time) {
long now = System.currentTimeMillis();
long diff = now - time;
if (diff < 1000 * 60) {
return "刚刚";
} else if (diff < 1000 * 60 * 60) {
long minutes = (diff / (1000 * 60));
return minutes + "分钟前";
} else if (diff < 1000 * 60 * 60 * 24) {
long hours = (diff / (1000 * 60 * 60));
return hours + "小时前";
} else {
long days = (diff / (1000 * 60 * 60 * 24));
return days + "天前";
}
}
Android 时间戳转多久之前
最新推荐文章于 2024-07-24 11:41:38 发布