|
|||||||||
| 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 |
| Constructor Summary | |
|---|---|
TimeUnitFormat()
Create empty format. |
|
TimeUnitFormat(Locale locale)
Create TimeUnitFormat given a Locale. |
|
TimeUnitFormat(ULocale locale)
Create TimeUnitFormat given a ULocale. |
|
| 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 |
| Constructor Detail |
|---|
public TimeUnitFormat()
public TimeUnitFormat(ULocale locale)
public TimeUnitFormat(Locale locale)
| Method Detail |
|---|
public TimeUnitFormat setLocale(ULocale locale)
public TimeUnitFormat setLocale(Locale locale)
public TimeUnitFormat setNumberFormat(NumberFormat format)
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 Format
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||