码迷,mamicode.com
首页 > 微信 > 详细

仿照微信朋友圈时间显示java实现

时间:2020-04-06 15:50:38      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:get   time()   color   axis   span   return   seconds   gettime   style   

自己

    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 + "天前 ";
    }

 

结束

仿照微信朋友圈时间显示java实现

标签:get   time()   color   axis   span   return   seconds   gettime   style   

原文地址:https://www.cnblogs.com/it-deepinmind/p/12642201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!