自己

    public static String getPrivateDateTimeAxis(Date date){
        if(date == null){
            return "";
        }
        SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        String createTime = sf.format(date);
        int days = getDayBetweenDays(date,new Date());
        if(days == 0){
            return "今天 " + createTime.split(" ")[1];
        }else if(days == 1){
            return "昨天 " + createTime.split(" ")[1];
        }
        return createTime;
    }

所有

    public static String getPublicDateTimeAxis(Date date){
        if(date == null){
            return "";
        }
        Date current = new Date();
        int days = getDayBetweenDays(date,current);
        if(days == 0){
            long time = current.getTime() - date.getTime();
            long seconds = time/1000;
            long minutes = seconds/60;
            long hours = minutes/60;
            if(minutes < 1){
                return "刚刚";
            }else if(minutes >= 1 && minutes < 60){
                return minutes + "分钟前";
            }
            return hours + "小时前";
        }else if(days == 1){
            return "昨天";
        }
        return days + "天前 ";
    }

 

结束

相关文章:

  • 2021-06-22
  • 2021-07-18
  • 2021-12-16
  • 2021-09-12
  • 2021-11-17
  • 2021-12-15
  • 2021-10-10
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2021-10-20
  • 2021-06-07
  • 2022-01-03
  • 2021-12-21
  • 2021-10-09
  • 2021-12-31
相关资源
相似解决方案