|
@@ -450,6 +450,31 @@ public class DateFunc {
|
|
|
return sdt.format(date);
|
|
return sdt.format(date);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static String getPassTime(Date date) {
|
|
|
|
|
+ long second = (System.currentTimeMillis() - date.getTime())/1000;
|
|
|
|
|
+ if(second < 60) {
|
|
|
|
|
+ return "刚刚";
|
|
|
|
|
+ }
|
|
|
|
|
+ long minute = second/60;
|
|
|
|
|
+ if(minute/60 < 1) {
|
|
|
|
|
+ return minute + "分钟前";
|
|
|
|
|
+ }
|
|
|
|
|
+ long hour = minute/60;
|
|
|
|
|
+ if(hour/24 < 1) {
|
|
|
|
|
+ return hour+"小时前";
|
|
|
|
|
+ }
|
|
|
|
|
+ long day = hour/24;
|
|
|
|
|
+ if(day/30 < 1) {
|
|
|
|
|
+ return day+"天前";
|
|
|
|
|
+ }
|
|
|
|
|
+ long month = day/30;
|
|
|
|
|
+ if(month/12 < 1) {
|
|
|
|
|
+ return month+"月前";
|
|
|
|
|
+ }
|
|
|
|
|
+ long year = month/12;
|
|
|
|
|
+ return year+"年前";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
// 验证 SimpleDateFormat 线程非安全
|
|
// 验证 SimpleDateFormat 线程非安全
|