com.ibm.icu.text
Class TimeUnitFormat

java.lang.Object
  extended by java.text.Format
      extended by com.ibm.icu.text.UFormat
          extended by com.ibm.icu.text.MeasureFormat
              extended by com.ibm.icu.text.TimeUnitFormat
All Implemented Interfaces:
Serializable, Cloneable

public class TimeUnitFormat
extends MeasureFormat

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:
TimeUnitAmount, TimeUnitFormat, Serialized Form
Status:
Draft ICU 4.0.

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

TimeUnitFormat

public TimeUnitFormat()
Create empty format. Use setLocale and/or setFormat to modify.

Status:
Draft ICU 4.0.

TimeUnitFormat

public TimeUnitFormat(ULocale locale)
Create TimeUnitFormat given a ULocale.

Status:
Draft ICU 4.0.

TimeUnitFormat

public TimeUnitFormat(Locale locale)
Create TimeUnitFormat given a Locale.

Status:
Draft ICU 4.0.
Method Detail

setLocale

public TimeUnitFormat setLocale(ULocale locale)
Set the locale used for formatting or parsing.

Returns:
this, for chaining.
Status:
Draft ICU 4.0.

setLocale

public TimeUnitFormat setLocale(Locale locale)
Set the locale used for formatting or parsing.

Returns:
this, for chaining.
Status:
Draft ICU 4.0.

setNumberFormat

public TimeUnitFormat setNumberFormat(NumberFormat format)
Set the format used for formatting or parsing. If null or not available, use the getNumberInstance(locale).

Returns:
this, for chaining.
Status:
Draft ICU 4.0.

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Format a TimeUnitAmount.

Specified by:
format in class Format
See Also:
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
Status:
Draft ICU 4.0.

parseObject

public Object parseObject(String source,
                          ParsePosition pos)
Parse a TimeUnitAmount.

Specified by:
parseObject in class Format
Status:
Draft ICU 4.0.


Copyright (c) 2009 IBM Corporation and others.