|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.text.Format
com.ibm.icu.text.UFormat
com.ibm.icu.text.MeasureFormat
com.ibm.icu.text.TimeUnitFormat
public class TimeUnitFormat
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) {
}
TimeUnitAmount,
TimeUnitFormat,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.text.Format |
|---|
Format.Field |
| Field Summary | |
|---|---|
static int |
ABBREVIATED_NAME
Constant for abbreviated name style format. |
static int |
FULL_NAME
Constant for full name style format. |
| Constructor Summary | |
|---|---|
TimeUnitFormat()
Create empty format using full name style, for example, "hours". |
|
TimeUnitFormat(Locale locale)
Create TimeUnitFormat given a Locale, and using full name style. |
|
TimeUnitFormat(Locale locale,
int style)
Create TimeUnitFormat given a Locale and a formatting style: full or abbreviated. |
|
TimeUnitFormat(ULocale locale)
Create TimeUnitFormat given a ULocale, and using full name style. |
|
TimeUnitFormat(ULocale locale,
int style)
Create TimeUnitFormat given a ULocale and a formatting style: full or abbreviated. |
|
| Method Summary | |
|---|---|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Format a TimeUnitAmount. |
Object |
parseObject(String source,
ParsePosition pos)
Parse a TimeUnitAmount. |
TimeUnitFormat |
setLocale(Locale locale)
Set the locale used for formatting or parsing. |
TimeUnitFormat |
setLocale(ULocale locale)
Set the locale used for formatting or parsing. |
TimeUnitFormat |
setNumberFormat(NumberFormat format)
Set the format used for formatting or parsing. |
| Methods inherited from class com.ibm.icu.text.MeasureFormat |
|---|
getCurrencyFormat, getCurrencyFormat |
| Methods inherited from class com.ibm.icu.text.UFormat |
|---|
getLocale |
| Methods inherited from class java.text.Format |
|---|
clone, format, formatToCharacterIterator, parseObject |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int FULL_NAME
public static final int ABBREVIATED_NAME
| Constructor Detail |
|---|
public TimeUnitFormat()
public TimeUnitFormat(ULocale locale)
locale - locale of this time unit formatter.public TimeUnitFormat(Locale locale)
locale - locale of this time unit formatter.
public TimeUnitFormat(ULocale locale,
int style)
locale - locale of this time unit formatter.style - format style, either FULL_NAME or ABBREVIATED_NAME style.
IllegalArgumentException - if the style is not FULL_NAME or
ABBREVIATED_NAME style.
public TimeUnitFormat(Locale locale,
int style)
| Method Detail |
|---|
public TimeUnitFormat setLocale(ULocale locale)
locale - locale of this time unit formatter.
public TimeUnitFormat setLocale(Locale locale)
locale - locale of this time unit formatter.
public TimeUnitFormat setNumberFormat(NumberFormat format)
format - the number formatter.
public StringBuffer format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
format in class FormatFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
public Object parseObject(String source,
ParsePosition pos)
parseObject in class FormatFormat.parseObject(java.lang.String, java.text.ParsePosition)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||