Esempio n. 1
0
  private static String subFormatDate(Calendar cal) {
    // Format time
    StringBuffer formatedDate = new StringBuffer();

    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.YEAR), 4));
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.MONTH) + 1, 2));
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.DATE), 2));
    formatedDate.append(t);
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.HOUR_OF_DAY), 2));
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.MINUTE), 2));
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.SECOND), 2));
    formatedDate.append(zeroPaddingNumber(cal.get(Calendar.MILLISECOND), 3));
    return formatedDate.toString();
  }
Esempio n. 2
0
  /**
   * this method converts into a string in ISO8601 format representing relative time from the
   * current time
   *
   * @param millisec is the number of milliseconds from now
   * @return a String, e.g. "+00000000T010000000" to represent one hour from now
   */
  public static String toRelativeTimeString(long millisec) {
    StringBuffer str = new StringBuffer();

    if (millisec > 0) str.append(plus);
    else {
      str.append(minus);
      millisec = (-millisec); // get only the absolute value
    }

    long tmp = millisec / 1000;
    long msec = millisec - tmp * 1000;
    millisec = tmp;

    tmp = millisec / 60;
    long sec = millisec - tmp * 60;
    millisec = tmp;

    tmp = millisec / 60;
    long min = millisec - tmp * 60;
    millisec = tmp;

    tmp = millisec / 24;
    long h = millisec - tmp * 24;
    millisec = tmp;

    tmp = millisec / 30;
    long day = millisec - tmp * 30;
    millisec = tmp;

    tmp = millisec / 12;
    long mon = millisec - tmp * 12;
    millisec = tmp;

    long year = millisec;

    str.append(zeroPaddingNumber(year, 4));
    str.append(zeroPaddingNumber(mon, 2));
    str.append(zeroPaddingNumber(day, 2));
    str.append(t);
    str.append(zeroPaddingNumber(h, 2));
    str.append(zeroPaddingNumber(min, 2));
    str.append(zeroPaddingNumber(sec, 2));
    str.append(zeroPaddingNumber(msec, 3));
    return str.toString();
  }