Class TimeUnitFormat
java.lang.Object
java.text.Format
com.ibm.icu.text.UFormat
com.ibm.icu.text.MeasureFormat
com.ibm.icu.text.TimeUnitFormat
- All Implemented Interfaces:
Serializable, Cloneable
Deprecated.
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Code Sample:
// create a time unit instance.
// only SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, and YEAR are supported
TimeUnit timeUnit = TimeUnit.SECOND;
// create time unit amount instance - a combination of Number and time unit
TimeUnitAmount source = new TimeUnitAmount(2, timeUnit);
// create time unit format instance
TimeUnitFormat format = new TimeUnitFormat();
// set the locale of time unit format
format.setLocale(new ULocale("en"));
// format a time unit amount
String formatted = format.format(source);
System.out.println(formatted);
try {
// parse a string into time unit amount
TimeUnitAmount result = (TimeUnitAmount) format.parseObject(formatted);
// result should equal to source
} catch (ParseException e) {
}
- Author:
- markdavis
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class MeasureFormat
MeasureFormat.FormatWidthNested classes/interfaces inherited from class UFormat
UFormat.SpanFieldModifier and TypeClassDescriptionstatic classA field that represents a span of text that may be composed with other fields.Nested classes/interfaces inherited from class Format
Format.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated.ICU 53 seeMeasureFormat.FormatWidthstatic final intDeprecated.ICU 53 seeMeasureFormat.FormatWidth -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.ICU 53 useMeasureFormatinstead.TimeUnitFormat(ULocale locale) Deprecated.ICU 53 useMeasureFormatinstead.TimeUnitFormat(ULocale locale, int style) Deprecated.ICU 53 useMeasureFormatinstead.TimeUnitFormat(Locale locale) Deprecated.ICU 53 useMeasureFormatinstead.TimeUnitFormat(Locale locale, int style) Deprecated.ICU 53 useMeasureFormatinstead. -
Method Summary
Modifier and TypeMethodDescriptionclone()Deprecated.ICU 53 seeMeasureFormatDeprecated.ICU 53 seeMeasureFormat.parseObject(String source, ParsePosition pos) Deprecated.ICU 53 seeMeasureFormat.Deprecated.ICU 53 seeMeasureFormat.Deprecated.ICU 53 seeMeasureFormat.setNumberFormat(NumberFormat format) Deprecated.ICU 53 seeMeasureFormat.Methods inherited from class MeasureFormat
equals, format, formatMeasurePerUnit, formatMeasures, formatMeasures, getCurrencyFormat, getCurrencyFormat, getCurrencyFormat, getInstance, getInstance, getInstance, getInstance, getLocale, getRangeFormat, getUnitDisplayName, getWidth, hashCodeModifier and TypeMethodDescriptionfinal booleanTwo MeasureFormats, a and b, are equal if and only if they have the same formatWidth, locale, and equal number formats.format(Object obj, StringBuffer toAppendTo, FieldPosition fpos) Able to format Collection<?formatMeasurePerUnit(Measure measure, MeasureUnit perUnit, StringBuilder appendTo, FieldPosition pos) Formats a single measure per unit.final StringformatMeasures(Measure... measures) Format a sequence of measures.formatMeasures(StringBuilder appendTo, FieldPosition fpos, Measure... measures) Formats a sequence of measures.static MeasureFormatReturn a formatter for CurrencyAmount objects in the defaultFORMATlocale.static MeasureFormatgetCurrencyFormat(ULocale locale) Return a formatter for CurrencyAmount objects in the given locale.static MeasureFormatgetCurrencyFormat(Locale locale) Return a formatter for CurrencyAmount objects in the givenLocale.static MeasureFormatgetInstance(ULocale locale, MeasureFormat.FormatWidth formatWidth) Create a format from the locale, formatWidth, and format.static MeasureFormatgetInstance(ULocale locale, MeasureFormat.FormatWidth formatWidth, NumberFormat format) Create a format from the locale, formatWidth, and format.static MeasureFormatgetInstance(Locale locale, MeasureFormat.FormatWidth formatWidth) Create a format from theLocaleand formatWidth.static MeasureFormatgetInstance(Locale locale, MeasureFormat.FormatWidth formatWidth, NumberFormat format) Create a format from theLocale, formatWidth, and format.final ULocaleGet the locale of this instance.static StringgetRangeFormat(ULocale forLocale, MeasureFormat.FormatWidth width) Deprecated.This API is ICU internal only.Gets the display name of the specifiedMeasureUnitcorresponding to the current locale and format width.getWidth()Get the format width this instance is using.final inthashCode()Methods inherited from class UFormat
getLocaleModifier and TypeMethodDescriptionfinal ULocalegetLocale(ULocale.Type type) Return the locale that was used to create this object, or null.Methods inherited from class Format
format, formatToCharacterIterator, parseObject
-
Field Details
-
FULL_NAME
Deprecated.ICU 53 seeMeasureFormat.FormatWidthConstant for full name style format. For example, the full name for "hour" in English is "hour" or "hours".- See Also:
-
ABBREVIATED_NAME
Deprecated.ICU 53 seeMeasureFormat.FormatWidthConstant for abbreviated name style format. For example, the abbreviated name for "hour" in English is "hr" or "hrs".- See Also:
-
-
Constructor Details
-
TimeUnitFormat
Deprecated.ICU 53 useMeasureFormatinstead.Create empty format using full name style, for example, "hours". Use setLocale and/or setFormat to modify. -
TimeUnitFormat
Deprecated.ICU 53 useMeasureFormatinstead.Create TimeUnitFormat given a ULocale, and using full name style.- Parameters:
locale- locale of this time unit formatter.
-
TimeUnitFormat
Deprecated.ICU 53 useMeasureFormatinstead.Create TimeUnitFormat given a Locale, and using full name style.- Parameters:
locale- locale of this time unit formatter.
-
TimeUnitFormat
Deprecated.ICU 53 useMeasureFormatinstead.Create TimeUnitFormat given a ULocale and a formatting style.- Parameters:
locale- locale of this time unit formatter.style- format style, either FULL_NAME or ABBREVIATED_NAME style.- Throws:
IllegalArgumentException- if the style is not FULL_NAME or ABBREVIATED_NAME style.
-
TimeUnitFormat
Deprecated.ICU 53 useMeasureFormatinstead.Create TimeUnitFormat given a Locale and a formatting style.
-
-
Method Details
-
setLocale
Deprecated.ICU 53 seeMeasureFormat.Set the locale used for formatting or parsing.- Parameters:
locale- locale of this time unit formatter.- Returns:
- this, for chaining.
-
setLocale
Deprecated.ICU 53 seeMeasureFormat.Set the locale used for formatting or parsing.- Parameters:
locale- locale of this time unit formatter.- Returns:
- this, for chaining.
-
setNumberFormat
Deprecated.ICU 53 seeMeasureFormat.Set the format used for formatting or parsing. Passing null is equivalent to passingNumberFormat.getNumberInstance(ULocale).- Parameters:
format- the number formatter.- Returns:
- this, for chaining.
-
getNumberFormat
Deprecated.ICU 53 seeMeasureFormat.Get a copy of the number format.- Overrides:
getNumberFormatin classMeasureFormat
-
parseObject
Deprecated.ICU 53 seeMeasureFormat.Parse a TimeUnitAmount.- Overrides:
parseObjectin classMeasureFormat- See Also:
-
clone
Deprecated.ICU 53 seeMeasureFormat
-
MeasureFormatinstead.