Exemplo n.º 1
0
  /**
   * Some test code.
   *
   * @param args ignored.
   */
  public static void main(String[] args) {
    GregorianCalendar c0 = new GregorianCalendar(2006, 10, 1, 0, 0, 0);
    GregorianCalendar c1 = new GregorianCalendar(2006, 10, 1, 11, 37, 43);
    c1.set(Calendar.MILLISECOND, 123);

    System.out.println("Default: ");
    RelativeDateFormat rdf = new RelativeDateFormat(c0.getTime().getTime());
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Hide milliseconds: ");
    rdf.setSecondFormatter(new DecimalFormat("0"));
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Show zero day output: ");
    rdf.setShowZeroDays(true);
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Alternative suffixes: ");
    rdf.setShowZeroDays(false);
    rdf.setDaySuffix(":");
    rdf.setHourSuffix(":");
    rdf.setMinuteSuffix(":");
    rdf.setSecondSuffix("");
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();
  }
Exemplo n.º 2
0
 /**
  * Returns a clone of this instance.
  *
  * @return A clone.
  */
 public Object clone() {
   RelativeDateFormat clone = (RelativeDateFormat) super.clone();
   clone.dayFormatter = (NumberFormat) this.dayFormatter.clone();
   clone.secondFormatter = (NumberFormat) this.secondFormatter.clone();
   return clone;
 }