- java.lang.Object
-
- java.text.Format
-
- java.text.DateFormat
-
- org.jfree.chart.text.format.RelativeDateFormat
-
- All Implemented Interfaces:
Serializable,Cloneable
public class RelativeDateFormat extends DateFormat
A formatter that formats dates to show the elapsed time relative to some base date.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.text.DateFormat
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 Description RelativeDateFormat()Creates a new instance with base milliseconds set to zero.RelativeDateFormat(long baseMillis)Creates a new instance.RelativeDateFormat(Date time)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()Returns a clone of this instance.booleanequals(Object obj)Tests this formatter for equality with an arbitrary object.StringBufferformat(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).longgetBaseMillis()Returns the base date/time used to calculate the elapsed time for display.StringgetDaySuffix()Returns the string that is appended to the day count.StringgetHourSuffix()Returns the string that is appended to the hour count.StringgetMinuteSuffix()Returns the string that is appended to the minute count.StringgetPositivePrefix()Returns the string that is prepended to the format if the relative time is positive.StringgetSecondSuffix()Returns the string that is appended to the second count.booleangetShowZeroDays()Returns the flag that controls whether or not zero day counts are shown in the formatted output.booleangetShowZeroHours()Returns the flag that controls whether or not zero hour counts are shown in the formatted output.inthashCode()Returns a hash code for this instance.Dateparse(String source, ParsePosition pos)Parses the given string (not implemented).voidsetBaseMillis(long baseMillis)Sets the base date/time used to calculate the elapsed time for display.voidsetDayFormatter(NumberFormat formatter)Sets the formatter for the days.voidsetDaySuffix(String suffix)Sets the string that is appended to the day count.voidsetHourFormatter(NumberFormat formatter)Sets the formatter for the hours.voidsetHourSuffix(String suffix)Sets the string that is appended to the hour count.voidsetMinuteFormatter(NumberFormat formatter)Sets the formatter for the minutes.voidsetMinuteSuffix(String suffix)Sets the string that is appended to the minute count.voidsetPositivePrefix(String prefix)Sets the string that is prepended to the format if the relative time is positive.voidsetSecondFormatter(NumberFormat formatter)Sets the formatter for the seconds and milliseconds.voidsetSecondSuffix(String suffix)Sets the string that is appended to the second count.voidsetShowZeroDays(boolean show)Sets the flag that controls whether or not zero day counts are shown in the formatted output.voidsetShowZeroHours(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
-
-
-
-
Constructor Detail
-
RelativeDateFormat
public RelativeDateFormat()
Creates a new instance with base milliseconds set to zero.
-
RelativeDateFormat
public RelativeDateFormat(Date time)
Creates a new instance.- Parameters:
time- the date/time (nullnot permitted).
-
RelativeDateFormat
public RelativeDateFormat(long baseMillis)
Creates a new instance.- Parameters:
baseMillis- the time zone (nullnot 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 asjava.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.
- 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.- See Also:
getShowZeroHours()
-
getPositivePrefix
public String getPositivePrefix()
Returns the string that is prepended to the format if the relative time is positive.- Returns:
- The string (never
null). - See Also:
setPositivePrefix(String)
-
setPositivePrefix
public void setPositivePrefix(String prefix)
Sets the string that is prepended to the format if the relative time is positive.- Parameters:
prefix- the prefix (nullnot permitted).- See Also:
getPositivePrefix()
-
setDayFormatter
public void setDayFormatter(NumberFormat formatter)
Sets the formatter for the days.- Parameters:
formatter- the formatter (nullnot permitted).
-
getDaySuffix
public String getDaySuffix()
Returns the string that is appended to the day count.- Returns:
- The string.
- See Also:
setDaySuffix(String)
-
setDaySuffix
public void setDaySuffix(String suffix)
Sets the string that is appended to the day count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getDaySuffix()
-
setHourFormatter
public void setHourFormatter(NumberFormat formatter)
Sets the formatter for the hours.- Parameters:
formatter- the formatter (nullnot permitted).
-
getHourSuffix
public String getHourSuffix()
Returns the string that is appended to the hour count.- Returns:
- The string.
- See Also:
setHourSuffix(String)
-
setHourSuffix
public void setHourSuffix(String suffix)
Sets the string that is appended to the hour count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getHourSuffix()
-
setMinuteFormatter
public void setMinuteFormatter(NumberFormat formatter)
Sets the formatter for the minutes.- Parameters:
formatter- the formatter (nullnot permitted).
-
getMinuteSuffix
public String getMinuteSuffix()
Returns the string that is appended to the minute count.- Returns:
- The string.
- See Also:
setMinuteSuffix(String)
-
setMinuteSuffix
public void setMinuteSuffix(String suffix)
Sets the string that is appended to the minute count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getMinuteSuffix()
-
getSecondSuffix
public String getSecondSuffix()
Returns the string that is appended to the second count.- Returns:
- The string.
- See Also:
setSecondSuffix(String)
-
setSecondSuffix
public void setSecondSuffix(String suffix)
Sets the string that is appended to the second count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getSecondSuffix()
-
setSecondFormatter
public void setSecondFormatter(NumberFormat formatter)
Sets the formatter for the seconds and milliseconds.- Parameters:
formatter- the formatter (nullnot permitted).
-
format
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)
Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).- Specified by:
formatin classDateFormat- Parameters:
date- the date.toAppendTo- the string buffer.fieldPosition- the field position.- Returns:
- The formatted date.
-
parse
public Date parse(String source, ParsePosition pos)
Parses the given string (not implemented).- Specified by:
parsein classDateFormat- Parameters:
source- the date string.pos- the parse position.- Returns:
null, as this method has not been implemented.
-
equals
public boolean equals(Object obj)
Tests this formatter for equality with an arbitrary object.- Overrides:
equalsin classDateFormat- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code for this instance.- Overrides:
hashCodein classDateFormat- Returns:
- A hash code.
-
clone
public Object clone()
Returns a clone of this instance.- Overrides:
clonein classDateFormat- Returns:
- A clone.
-
-