Exemplo n.º 1
0
  /**
   * 取得时间描述 日 mm月dd日 月 yy年mm月 季 yy年×季度(x=1/2/3/4) 年 yy年
   *
   * @param granularity 粒度
   * @param statisticDate 时间
   * @return 时间对应粒度的描述
   */
  public String getTimedes2(String granularity, String statisticDate) {
    String timedes = "";
    Date date = DateUtils.stringToDateShort(statisticDate);
    String year = "", month = "01", day = "01";
    year = DateUtils.getYear(date).substring(2, 4);
    month = DateUtils.getMonth(date);
    day = DateUtils.getDay(date);
    if (granularity.equals("1")) { // 日
      timedes = month + "月" + day + "日";
      ;
    } else if (granularity.equals("4")) { // 月
      timedes = year + "年" + month + "月";

    } else if (granularity.equals("8")) { // 季
      String quarter = month + "-" + day;
      if (quarter.equals("03-31")) {
        timedes = year + "年1季度";
      } else if (quarter.equals("06-30")) {
        timedes = year + "年2季度";
      } else if (quarter.equals("09-30")) {
        timedes = year + "年3季度";
      } else if (quarter.equals("12-31")) {
        timedes = year + "年4季度";
      }
    } else if (granularity.equals("32")) { // 年
      timedes = year + "年";
    }
    return timedes;
  }
Exemplo n.º 2
0
  /**
   * 取得日以上粒度起始时间
   *
   * @param granularity 粒度
   * @param statisticDate 结束时间
   * @return 起始时间
   */
  public String getEndDate(String granularity, String statisticDate) {
    String beginDate = "";
    Date date = DateUtils.stringToDateShort(statisticDate);
    Date beginDateTemp = null;

    if (granularity.equals("1")) { // 日
      beginDateTemp = date;
    }
    if (granularity.equals("2")) { // 周
      beginDateTemp = this.getWeekEnd(date);
    }
    if (granularity.equals("3")) { // 旬
      beginDateTemp = this.getPeriodEnd(date);
    } else if (granularity.equals("4")) { // 月
      beginDateTemp = this.getMonthEnd(date);
    } else if (granularity.equals("5")) { // 季
      beginDateTemp = this.getSeasonEnd(date);
    } else if (granularity.equals("6")) { // 半年
      beginDateTemp = this.getHalfYearEnd(date);
    } else if (granularity.equals("7")) { // 年
      beginDateTemp = this.getYearEnd(date);
    }

    beginDate = DateUtils.dateToStringShort(beginDateTemp);
    return beginDate;
  }
Exemplo n.º 3
0
  /**
   * 比较日期大小
   *
   * @author gaofeng
   * @param dateString1
   * @param dateString2
   * @return
   */
  public int compareDate(Date date1, Date date2) {
    int rslt = 0;

    int intdate1 = Integer.parseInt(DateUtils.FormatDate(date1, "yyyyMMdd"));
    int intdate2 = Integer.parseInt(DateUtils.FormatDate(date2, "yyyyMMdd"));
    if (intdate1 > intdate2) {
      rslt = 1;
    } else if (intdate1 < intdate2) {
      rslt = -1;
    } else {
      rslt = 0;
    }

    return rslt;
  }
Exemplo n.º 4
0
  /**
   * 比较日期大小
   *
   * @author gaofeng
   * @param dateString1
   * @param dateString2
   * @return rslt
   */
  public int compareDateString(String dateString1, String dateString2) {
    int rslt = 0;
    java.util.Date date1 = DateUtils.stringToDate(dateString1, "yyyy-MM-dd");
    java.util.Date date2 = DateUtils.stringToDate(dateString2, "yyyy-MM-dd");

    int intdate1 = Integer.parseInt(DateUtils.FormatDate(date1, "yyyyMMdd"));
    int intdate2 = Integer.parseInt(DateUtils.FormatDate(date2, "yyyyMMdd"));
    if (intdate1 > intdate2) {
      rslt = 1;
    } else if (intdate1 < intdate2) {
      rslt = -1;
    } else {
      rslt = 0;
    }

    return rslt;
  }