Class RelativeDateFormat
java.lang.Object
java.text.Format
com.ibm.icu.text.UFormat
com.ibm.icu.text.DateFormat
com.ibm.icu.impl.RelativeDateFormat
- All Implemented Interfaces:
Serializable, Cloneable
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classstatic classNested classes/interfaces inherited from class DateFormat
DateFormat.BooleanAttribute, DateFormat.Field, DateFormat.HourCycleNested classes/interfaces inherited from class UFormat
UFormat.SpanField -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BreakIteratorprivate booleanprivate booleanprivate booleanprivate booleanprivate MessageFormatprivate DateFormatprivate Stringprivate List<RelativeDateFormat.URelativeString> (package private) intprivate SimpleDateFormat(package private) ULocaleprivate DateFormatprivate String(package private) intprivate static final longserial version (generated)Fields inherited from class DateFormat
ABBR_GENERIC_TZ, ABBR_MONTH, ABBR_MONTH_DAY, ABBR_MONTH_WEEKDAY_DAY, ABBR_QUARTER, ABBR_SPECIFIC_TZ, ABBR_STANDALONE_MONTH, ABBR_UTC_TZ, ABBR_WEEKDAY, AM_PM_FIELD, AM_PM_MIDNIGHT_NOON_FIELD, calendar, DATE_FIELD, DATE_SKELETONS, DAY, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, DOW_LOCAL_FIELD, ERA_FIELD, EXTENDED_YEAR_FIELD, FIELD_COUNT, FLEXIBLE_DAY_PERIOD_FIELD, FRACTIONAL_SECOND_FIELD, FULL, GENERIC_TZ, HOUR, HOUR_GENERIC_TZ, HOUR_MINUTE, HOUR_MINUTE_GENERIC_TZ, HOUR_MINUTE_SECOND, HOUR_MINUTE_TZ, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR_TZ, HOUR0_FIELD, HOUR1_FIELD, HOUR24, HOUR24_MINUTE, HOUR24_MINUTE_SECOND, JP_ERA_2019_JA, JP_ERA_2019_NARROW, JP_ERA_2019_ROOT, JULIAN_DAY_FIELD, LOCATION_TZ, LONG, MEDIUM, MILLISECOND_FIELD, MILLISECONDS_IN_DAY_FIELD, MINUTE, MINUTE_FIELD, MINUTE_SECOND, MONTH, MONTH_DAY, MONTH_FIELD, MONTH_WEEKDAY_DAY, NONE, NUM_MONTH, NUM_MONTH_DAY, NUM_MONTH_WEEKDAY_DAY, numberFormat, QUARTER, QUARTER_FIELD, RELATIVE, RELATIVE_DEFAULT, RELATIVE_FULL, RELATIVE_LONG, RELATIVE_MEDIUM, RELATIVE_SHORT, SECOND, SECOND_FIELD, SHORT, SPECIFIC_TZ, STANDALONE_DAY_FIELD, STANDALONE_MONTH, STANDALONE_MONTH_FIELD, STANDALONE_QUARTER_FIELD, TIME_SEPARATOR, TIME_SKELETONS, TIMEZONE_FIELD, TIMEZONE_GENERIC_FIELD, TIMEZONE_ISO_FIELD, TIMEZONE_ISO_LOCAL_FIELD, TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD, TIMEZONE_RFC_FIELD, TIMEZONE_SPECIAL_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, WEEKDAY, YEAR, YEAR_ABBR_MONTH, YEAR_ABBR_MONTH_DAY, YEAR_ABBR_MONTH_WEEKDAY_DAY, YEAR_ABBR_QUARTER, YEAR_FIELD, YEAR_MONTH, YEAR_MONTH_DAY, YEAR_MONTH_WEEKDAY_DAY, YEAR_NAME_FIELD, YEAR_NUM_MONTH, YEAR_NUM_MONTH_DAY, YEAR_NUM_MONTH_WEEKDAY_DAY, YEAR_QUARTER, YEAR_WOY_FIELD, ZONE_SKELETONS -
Constructor Summary
ConstructorsConstructorDescriptionRelativeDateFormat(int timeStyle, int dateStyle, ULocale locale, Calendar cal) -
Method Summary
Modifier and TypeMethodDescriptionprivate static intdayDifference(Calendar until) format(Calendar cal, StringBuffer toAppendTo, FieldPosition fieldPosition) Formats a date into a date/time string.private StringgetStringForDay(int day) Get the string at a specific offset.private voidinitCapitalizationContextInfo(ULocale locale) Set capitalizationOfRelativeUnitsForListOrMenu, capitalizationOfRelativeUnitsForStandAloneprivate CalendarinitializeCalendar(TimeZone zone, ULocale locale) initializes fCalendar from parameters.private MessageFormatinitializeCombinedFormat(Calendar cal, ULocale locale) private voidLoad the Date string arrayvoidparse(String text, Calendar cal, ParsePosition pos) Parses a date/time string according to the given parse position.voidsetContext(DisplayContext context) Set a particular DisplayContext value in the formatter, such as CAPITALIZATION_FOR_STANDALONE.Methods inherited from class DateFormat
clone, equals, format, format, format, format, format, getAvailableLocales, getAvailableULocales, getBooleanAttribute, getCalendar, getContext, getDateInstance, getDateInstance, getDateInstance, getDateInstance, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getInstance, getInstance, getInstance, getInstanceForSkeleton, getInstanceForSkeleton, getInstanceForSkeleton, getInstanceForSkeleton, getInstanceForSkeleton, getNumberFormat, getPatternInstance, getPatternInstance, getPatternInstance, getPatternInstance, getPatternInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isCalendarLenient, isLenient, parse, parse, parseObject, setBooleanAttribute, setCalendar, setCalendarLenient, setLenient, setNumberFormat, setTimeZoneMethods inherited from class Format
format, formatToCharacterIterator, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDserial version (generated)- See Also:
-
fDateFormat
-
fTimeFormat
-
fCombinedFormat
-
fDateTimeFormat
-
fDatePattern
-
fTimePattern
-
fDateStyle
int fDateStyle -
fTimeStyle
int fTimeStyle -
fLocale
ULocale fLocale -
fDates
-
combinedFormatHasDateAtStart
private boolean combinedFormatHasDateAtStart -
capitalizationInfoIsSet
private boolean capitalizationInfoIsSet -
capitalizationOfRelativeUnitsForListOrMenu
private boolean capitalizationOfRelativeUnitsForListOrMenu -
capitalizationOfRelativeUnitsForStandAlone
private boolean capitalizationOfRelativeUnitsForStandAlone -
capitalizationBrkIter
-
-
Constructor Details
-
RelativeDateFormat
-
-
Method Details
-
format
Description copied from class:DateFormatFormats a date into a date/time string.- Specified by:
formatin classDateFormat- Parameters:
cal- a Calendar set to the date and time to be formatted into a date/time string. When the calendar type is different from the internal calendar held by this DateFormat instance, the date and the time zone will be inherited from the input calendar, but other calendar field values will be calculated by the internal calendar.toAppendTo- the string buffer for the returning date/time string.fieldPosition- keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.- Returns:
- the formatted date/time string.
-
parse
Description copied from class:DateFormatParses a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Calendar that is equivalent to Date(837039928046). Before calling this method the caller should initialize the calendar in one of two ways (unless existing field information is to be kept): (1) clear the calendar, or (2) set the calendar to the current date (or to any date whose fields should be used to supply values that are missing in the parsed date). For example, Chinese calendar dates do not normally provide an era/cycle; in this case the calendar that is passed in should be set to a date within the era that should be assumed, normally the current era.By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
- Specified by:
parsein classDateFormat- Parameters:
text- The date/time string to be parsedcal- The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar.pos- On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.- See Also:
-
setContext
Description copied from class:DateFormatSet a particular DisplayContext value in the formatter, such as CAPITALIZATION_FOR_STANDALONE.- Overrides:
setContextin classDateFormat- Parameters:
context- The DisplayContext value to set.
-
getStringForDay
Get the string at a specific offset.- Parameters:
day- day offset ( -1, 0, 1, etc.. ). Does not require sorting by offset.- Returns:
- the string, or NULL if none at that location.
-
loadDates
private void loadDates()Load the Date string array -
initCapitalizationContextInfo
Set capitalizationOfRelativeUnitsForListOrMenu, capitalizationOfRelativeUnitsForStandAlone -
dayDifference
- Returns:
- the number of days in "until-now"
-
initializeCalendar
initializes fCalendar from parameters. Returns fCalendar as a convenience.- Parameters:
zone- Zone to be adopted, or NULL for TimeZone::createDefault().locale- Locale of the calendarstatus- Error code- Returns:
- the newly constructed fCalendar
-
initializeCombinedFormat
-