Android 时间戳转多久之前

   /**
     * 时间戳转为多久之前
     * @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,java,开发语言)