首页 > 代码库 > 时间工具

时间工具

public static String getTimeForShowing(String strTime)      {          System.out.println(strTime);        //        int year = Integer.parseInt(strTime.substring(0, 4));          //        int month = Integer.parseInt(strTime.substring(5, 7));          //日期          int day = Integer.parseInt(strTime.substring(8, 10));          //小时          int hour = Integer.parseInt(strTime.substring(11, 13));          //分钟          int minute = Integer.parseInt(strTime.substring(14, 16));          //        int second = Integer.parseInt(strTime.substring(17, 19));          Calendar now  = Calendar.getInstance();          Calendar dynamicT = Calendar.getInstance();          dynamicT.set(year, month - 1, day, hour, minute, second);          long intermill = (now.getTimeInMillis() - dynamicT.getTimeInMillis()) / 1000;          if (intermill < 60) {              //60秒以内              return "刚才";          } else if (intermill < 3600) {              //60分钟以内              return (intermill / 60) + "分钟前";          } else if (intermill < 3600 * 24) {              //24小时以内              return (intermill/(3600)) + "小时前";          } else if (intermill < 3600 * 24 * 30) {              //一个月以内              return (intermill / (3600 * 24)) + "天前";          } else if (intermill < 3600 * 24 * 365) {              //一年以内              return month + "月" + day + "日";          } else {              //一年以上              StringBuffer buff = new StringBuffer(Integer.toString(year)).append("年");              buff.append(month).append("月");              buff.append(day).append("日");              return  buff.toString() ;          }      } 
public static String getNow() {        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        return sdf.format(new Date());    }