Exemplo n.º 1
0
 /**
  * get seconds from a time format
  *
  * @param t
  */
 public void getSeconds(TimeFormat t) {
   if (t.remainder >= ONE_SECOND && t.remainder < ONE_MINUTE) {
     t.seconds = (t.remainder / ONE_SECOND);
     t.milliseconds = t.remainder -= (t.seconds * ONE_SECOND);
   } else {
     t.seconds = 0;
     t.milliseconds = t.remainder;
   }
 }
Exemplo n.º 2
0
  /**
   * test
   *
   * @param args
   */
  public static void main(String args[]) {
    String FORMAT = "D 'days,' HH 'hours,' mm 'minutes and ' ss 'seconds, 'zz 'milliseconds'";

    System.out.println(TimeFormat.format(FORMAT, 1000));
    System.out.println("ONE SECOND: " + TimeFormat.ONE_SECOND);
    System.out.println("ONE MINUTE: " + TimeFormat.ONE_MINUTE);
    System.out.println("ONE HOUR:   " + TimeFormat.ONE_HOUR);
    System.out.println("ONE DAY:    " + TimeFormat.ONE_DAY);

    for (int c = 0; c <= 5; c++) {
      System.out.println("============ Round to: " + c + " ==================");
      System.out.println("Time: " + TimeFormat.valueOf(Long.MAX_VALUE, c));
      System.out.println("Time: " + TimeFormat.valueOf(1236371400, c));
      System.out.println("Time: " + TimeFormat.format(FORMAT, 1236371400));
      System.out.println("Time: " + TimeFormat.valueOf(123613700, c));
      System.out.println("Time: " + TimeFormat.valueOf(700, c));
      System.out.println("Time: " + TimeFormat.valueOf(2001, c));
      System.out.println("Time: " + TimeFormat.valueOf(2101, c));
      System.out.println("Time: " + TimeFormat.valueOf(15, c));
      System.out.println("Time: " + TimeFormat.valueOf(999, c));
      System.out.println("Time: " + TimeFormat.valueOf(10000, c));
      System.out.println("Time: " + TimeFormat.valueOf(ONE_MINUTE * 10, c));
      System.out.println("Time: " + TimeFormat.valueOf(ONE_DAY * 10 + 101, c));
      System.out.println("Time: " + TimeFormat.valueOf(ONE_HOUR * 10, c));
      System.out.println("Time: " + TimeFormat.valueOf(ONE_HOUR + ONE_DAY + (ONE_MINUTE * 2), c));
      System.out.println(
          "Time: " + TimeFormat.format(FORMAT, ONE_HOUR + ONE_DAY + (ONE_MINUTE * 2)));
      System.out.println("================================================");
    }
  }
Exemplo n.º 3
0
  /** format with a date time */
  public static String format(String format, long time) {
    TimeFormat f = new TimeFormat(time);

    return f.parse(
        format, f.getDays(), f.getHours(), f.getMinutes(), f.getSeconds(), f.getMilliseconds());
  }
Exemplo n.º 4
0
  /**
   * return a string formatted version of time <code>t</code> rounding to <code>round</code>
   *
   * @param t
   * @param round
   * @return String value
   */
  public static String valueOf(long t, int round) {
    TimeFormat f = new TimeFormat(t, round);

    return f.toString();
  }
Exemplo n.º 5
0
 /**
  * update time
  *
  * @param t
  */
 public void getTime(TimeFormat t) {
   t.getTime();
 }
Exemplo n.º 6
0
 /**
  * get minutes from a time format
  *
  * @param t
  */
 public void getMinutes(TimeFormat t) {
   if (t.remainder >= ONE_MINUTE && t.remainder < ONE_HOUR) {
     t.minutes = (t.remainder / ONE_MINUTE);
     t.remainder -= (t.minutes * ONE_MINUTE);
   }
 }
Exemplo n.º 7
0
 /**
  * get hours from a time format
  *
  * @param t
  */
 public void getHours(TimeFormat t) {
   if (t.remainder >= ONE_HOUR && t.remainder < ONE_DAY) {
     t.hours = (t.remainder / ONE_HOUR);
     t.remainder -= (t.hours * ONE_HOUR);
   }
 }
Exemplo n.º 8
0
 /**
  * get days from a time format
  *
  * @param t
  */
 public void getDays(TimeFormat t) {
   if (t.remainder >= ONE_DAY) {
     t.days = (t.remainder / ONE_DAY);
     t.remainder -= (t.days * ONE_DAY);
   }
 }