Code example for Formatter

Methods: format, toString

0
    return (getTimeInMillis() > when);
  } 
 
  @Override 
  public String toString() {
    Formatter formatter = new Formatter();
    int year = get(YEAR);
    int month = get(MONTH)+1;
    int day = get(DAY_OF_MONTH);
    int hour = get(HOUR_OF_DAY);
    int min = get(MINUTE);
    int second = get(SECOND);
    if (date) {
      formatter.format("%04d-%02d-%02d", year, month, day);
    } else { 
      long offset = getTimeZone().getOffset(getTimeInMillis()) / (60000L);
      int hoffset = (int) (offset / 60L);
      int minoffset = (int) (offset % 60L);
      if (offset == 0) {
        formatter.format("%04d-%02d-%02dT%02d:%02d:%02dZ", year, month, day, hour, min,
            second);
      } else if (offset < 0) {
        formatter.format("%04d-%02d-%02dT%02d:%02d:%02d-%02d:%02d", year, month, day,
            hour, min, second, -hoffset, -minoffset);
      } else { 
        formatter.format("%04d-%02d-%02dT%02d:%02d:%02d+%02d:%02d", year, month, day,
            hour, min, second, hoffset, minoffset);
      } 
    } 
    return formatter.toString();
  } 
 
  /** 
   * @param b 
   */