/**    * 以友好的方式显示时间    *    * @param sdate    * @return    */   public static String friendly_time(String sdate) {       Date time = null;       if (TimeZoneUtil.isInEasternEightZones())           time = toDate(sdate);       else           time = TimeZoneUtil.transformTime(toDate(sdate),                   TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());       if (time == null) {           return "Unknown";       }       String ftime = "";       Calendar cal = Calendar.getInstance();       // 判断是否是同一天       String curDate = dateFormater2.get().format(cal.getTime());       String paramDate = dateFormater2.get().format(time);       if (curDate.equals(paramDate)) {           int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);           if (hour == 0)               ftime = Math.max(                       (cal.getTimeInMillis() - time.getTime()) / 60000, 1)                       + "分钟前";           else               ftime = hour + "小时前";           return ftime;       }       long lt = time.getTime() / 86400000;       long ct = cal.getTimeInMillis() / 86400000;       int days = (int) (ct - lt);       if (days == 0) {           int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);           if (hour == 0)               ftime = Math.max(                       (cal.getTimeInMillis() - time.getTime()) / 60000, 1)                       + "分钟前";           else               ftime = hour + "小时前";       } else if (days == 1) {           ftime = "昨天";       } else if (days == 2) {           ftime = "前天 ";       } else if (days > 2 && days < 31) {           ftime = days + "天前";       } else if (days >= 31 && days <= 2 * 31) {           ftime = "一个月前";       } else if (days > 2 * 31 && days <= 3 * 31) {           ftime = "2个月前";       } else if (days > 3 * 31 && days <= 4 * 31) {           ftime = "3个月前";       } else {           ftime = dateFormater2.get().format(time);       }       return ftime;   }

 

更多相关文章

  1. FlexboxLayout使用指南
  2. Android(安卓)studio 导入github工程
  3. Android之ShortCut[setResult方式]
  4. Android(安卓)-- App生成快捷方式
  5. Android当前时间的获取
  6. android 判断耳机是否插入的几种方式
  7. android 使用post方式上传文件
  8. android 中 LocalSocket的基本使用方法
  9. Android调试工具 —— TraceView [整理]

随机推荐

  1. Android 使用finalBitmap实现缓存读取
  2. android 图片LOMO效果
  3. 安卓开发-HttpClient使用
  4. CaysnPrinter开发包接口说明文档 - Print
  5. android 完美获取状态栏高度
  6. 几种判断应用(Android(安卓)App)前后台状
  7. Android Application Development, 1st E
  8. android 服务
  9. Android之Touch事件分发机制
  10. Android下拉列表控件spinner-andoid学习