org.jfree.chart.util

## Class RelativeDateFormat

- java.lang.Object
- - java.text.Format
  - - java.text.DateFormat
    - - org.jfree.chart.util.RelativeDateFormat

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable

    public class RelativeDateFormat
    extends java.text.DateFormat

A formatter that formats dates to show the elapsed time relative to some base date.

Since:
  1.0.3
See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class java.text.DateFormat

`java.text.DateFormat.Field`

### Field Summary

### Fields inherited from class java.text.DateFormat

`AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD`

### Constructor Summary

Constructors
Constructor and Description
`RelativeDateFormat()` Creates a new instance with base milliseconds set to zero.
`RelativeDateFormat(java.util.Date time)` Creates a new instance.
`RelativeDateFormat(long baseMillis)` Creates a new instance.

### Method Summary

Methods
`java.lang.Object` `clone()` Returns a clone of this instance.
`boolean` `equals(java.lang.Object obj)` Tests this formatter for equality with an arbitrary object.
`java.lang.StringBuffer` `format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)` Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).
`long` `getBaseMillis()` Returns the base date/time used to calculate the elapsed time for display.
`java.lang.String` `getDaySuffix()` Returns the string that is appended to the day count.
`java.lang.String` `getHourSuffix()` Returns the string that is appended to the hour count.
`java.lang.String` `getMinuteSuffix()` Returns the string that is appended to the minute count.
`java.lang.String` `getPositivePrefix()` Returns the string that is prepended to the format if the relative time is positive.
`java.lang.String` `getSecondSuffix()` Returns the string that is appended to the second count.
`boolean` `getShowZeroDays()` Returns the flag that controls whether or not zero day counts are shown in the formatted output.
`boolean` `getShowZeroHours()` Returns the flag that controls whether or not zero hour counts are shown in the formatted output.
`int` `hashCode()` Returns a hash code for this instance.
`static void` `main(java.lang.String[] args)` Some test code.
`java.util.Date` `parse(java.lang.String source, java.text.ParsePosition pos)` Parses the given string (not implemented).
`void` `setBaseMillis(long baseMillis)` Sets the base date/time used to calculate the elapsed time for display.
`void` `setDayFormatter(java.text.NumberFormat formatter)` Sets the formatter for the days.
`void` `setDaySuffix(java.lang.String suffix)` Sets the string that is appended to the day count.
`void` `setHourFormatter(java.text.NumberFormat formatter)` Sets the formatter for the hours.
`void` `setHourSuffix(java.lang.String suffix)` Sets the string that is appended to the hour count.
`void` `setMinuteFormatter(java.text.NumberFormat formatter)` Sets the formatter for the minutes.
`void` `setMinuteSuffix(java.lang.String suffix)` Sets the string that is appended to the minute count.
`void` `setPositivePrefix(java.lang.String prefix)` Sets the string that is prepended to the format if the relative time is positive.
`void` `setSecondFormatter(java.text.NumberFormat formatter)` Sets the formatter for the seconds and milliseconds.
`void` `setSecondSuffix(java.lang.String suffix)` Sets the string that is appended to the second count.
`void` `setShowZeroDays(boolean show)` Sets the flag that controls whether or not zero day counts are shown in the formatted output.
`void` `setShowZeroHours(boolean show)` Sets the flag that controls whether or not zero hour counts are shown in the formatted output.

### Methods inherited from class java.text.DateFormat

`format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone`

### Methods inherited from class java.text.Format

`format, formatToCharacterIterator, parseObject`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### RelativeDateFormat

    public RelativeDateFormat()

Creates a new instance with base milliseconds set to zero.

#### RelativeDateFormat

    public RelativeDateFormat(java.util.Date time)

Creates a new instance.

Parameters:
  `time` - the date/time (`null` not permitted).

#### RelativeDateFormat

    public RelativeDateFormat(long baseMillis)

Creates a new instance.

Parameters:
  `baseMillis` - the time zone (`null` not permitted).

### Method Detail

#### getBaseMillis

    public long getBaseMillis()

Returns the base date/time used to calculate the elapsed time for display.

Returns:
  The base date/time in milliseconds since 1-Jan-1970.
See Also:
  `setBaseMillis(long)`

#### setBaseMillis

    public void setBaseMillis(long baseMillis)

Sets the base date/time used to calculate the elapsed time for display. This should be specified in milliseconds using the same encoding as `java.util.Date`.

Parameters:
  `baseMillis` - the base date/time in milliseconds.
See Also:
  `getBaseMillis()`

#### getShowZeroDays

    public boolean getShowZeroDays()

Returns the flag that controls whether or not zero day counts are shown in the formatted output.

Returns:
  The flag.
See Also:
  `setShowZeroDays(boolean)`

#### setShowZeroDays

    public void setShowZeroDays(boolean show)

Sets the flag that controls whether or not zero day counts are shown in the formatted output.

Parameters:
  `show` - the flag.
See Also:
  `getShowZeroDays()`

#### getShowZeroHours

    public boolean getShowZeroHours()

Returns the flag that controls whether or not zero hour counts are shown in the formatted output.

Returns:
  The flag.
Since:
  1.0.10
See Also:
  `setShowZeroHours(boolean)`

#### setShowZeroHours

    public void setShowZeroHours(boolean show)

Sets the flag that controls whether or not zero hour counts are shown in the formatted output.

Parameters:
  `show` - the flag.
Since:
  1.0.10
See Also:
  `getShowZeroHours()`

#### getPositivePrefix

    public java.lang.String getPositivePrefix()

Returns the string that is prepended to the format if the relative time is positive.

Returns:
  The string (never `null`).
Since:
  1.0.10
See Also:
  `setPositivePrefix(String)`

#### setPositivePrefix

    public void setPositivePrefix(java.lang.String prefix)

Sets the string that is prepended to the format if the relative time is positive.

Parameters:
  `prefix` - the prefix (`null` not permitted).
Since:
  1.0.10
See Also:
  `getPositivePrefix()`

#### setDayFormatter

    public void setDayFormatter(java.text.NumberFormat formatter)

Sets the formatter for the days.

Parameters:
  `formatter` - the formatter (`null` not permitted).
Since:
  1.0.11

#### getDaySuffix

    public java.lang.String getDaySuffix()

Returns the string that is appended to the day count.

Returns:
  The string.
See Also:
  `setDaySuffix(String)`

#### setDaySuffix

    public void setDaySuffix(java.lang.String suffix)

Sets the string that is appended to the day count.

Parameters:
  `suffix` - the suffix (`null` not permitted).
See Also:
  `getDaySuffix()`

#### setHourFormatter

    public void setHourFormatter(java.text.NumberFormat formatter)

Sets the formatter for the hours.

Parameters:
  `formatter` - the formatter (`null` not permitted).
Since:
  1.0.11

#### getHourSuffix

    public java.lang.String getHourSuffix()

Returns the string that is appended to the hour count.

Returns:
  The string.
See Also:
  `setHourSuffix(String)`

#### setHourSuffix

    public void setHourSuffix(java.lang.String suffix)

Sets the string that is appended to the hour count.

Parameters:
  `suffix` - the suffix (`null` not permitted).
See Also:
  `getHourSuffix()`

#### setMinuteFormatter

    public void setMinuteFormatter(java.text.NumberFormat formatter)

Sets the formatter for the minutes.

Parameters:
  `formatter` - the formatter (`null` not permitted).
Since:
  1.0.11

#### getMinuteSuffix

    public java.lang.String getMinuteSuffix()

Returns the string that is appended to the minute count.

Returns:
  The string.
See Also:
  `setMinuteSuffix(String)`

#### setMinuteSuffix

    public void setMinuteSuffix(java.lang.String suffix)

Sets the string that is appended to the minute count.

Parameters:
  `suffix` - the suffix (`null` not permitted).
See Also:
  `getMinuteSuffix()`

#### getSecondSuffix

    public java.lang.String getSecondSuffix()

Returns the string that is appended to the second count.

Returns:
  The string.
See Also:
  `setSecondSuffix(String)`

#### setSecondSuffix

    public void setSecondSuffix(java.lang.String suffix)

Sets the string that is appended to the second count.

Parameters:
  `suffix` - the suffix (`null` not permitted).
See Also:
  `getSecondSuffix()`

#### setSecondFormatter

    public void setSecondFormatter(java.text.NumberFormat formatter)

Sets the formatter for the seconds and milliseconds.

Parameters:
  `formatter` - the formatter (`null` not permitted).

#### format

    public java.lang.StringBuffer format(java.util.Date date,
                                java.lang.StringBuffer toAppendTo,
                                java.text.FieldPosition fieldPosition)

Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).

Specified by:
  `format` in class `java.text.DateFormat`
Parameters:
  `date` - the date.
  `toAppendTo` - the string buffer.
  `fieldPosition` - the field position.
Returns:
  The formatted date.

#### parse

    public java.util.Date parse(java.lang.String source,
                       java.text.ParsePosition pos)

Parses the given string (not implemented).

Specified by:
  `parse` in class `java.text.DateFormat`
Parameters:
  `source` - the date string.
  `pos` - the parse position.
Returns:
  `null`, as this method has not been implemented.

#### equals

    public boolean equals(java.lang.Object obj)

Tests this formatter for equality with an arbitrary object.

Overrides:
  `equals` in class `java.text.DateFormat`
Parameters:
  `obj` - the object (`null` permitted).
Returns:
  A boolean.

#### hashCode

    public int hashCode()

Returns a hash code for this instance.

Overrides:
  `hashCode` in class `java.text.DateFormat`
Returns:
  A hash code.

#### clone

    public java.lang.Object clone()

Returns a clone of this instance.

Overrides:
  `clone` in class `java.text.DateFormat`
Returns:
  A clone.

#### main

    public static void main(java.lang.String[] args)

Some test code.

Parameters:
  `args` - ignored.