com.ibm.as400.ui.framework.java
Class TimeFormatter

java.lang.Object
  extended by com.ibm.as400.ui.framework.java.DataFormatter
      extended by com.ibm.as400.ui.framework.java.TimeFormatter

public class TimeFormatter
extends DataFormatter

Formatter for exchanging time values between DataBeans and user interface components. TimeFormatter formats Date objects and displays as times according to current locale, and parses time strings into Date objects. If parsing is unsuccessful, an IllegalUserDataException is thrown.

Times can be displayed and entered in different styles:

The DateFormat.DEFAULT system style is also available, which is the style used if no other style is specified.

The default Locale is used for all formatting and parsing.

Only the time portions of the Date object returned from parsing are meaningful.

Since:
v4r2m0
Version:
1.1, 05/19/99
Author:
B. Cragun
See Also:
DataBean, IllegalUserDataException, DateFormat

Constructor Summary
Constructor and Description
TimeFormatter()
          Constructs a TimeFormatter.
TimeFormatter(int style)
          Constructs a TimeFormatter with the specified style for time display.
 
Method Summary
Modifier and Type Method and Description
 String format(Date date)
          Format a date based on the current style set for the Time Formatter.
 String format(Object obj)
          Format a date based on the current style set for the Time Formatter.
 int getStyle()
          Gets the style to be used for formatting.
 Object parse(String source)
          Parses a string to produce a Date object.
 void setStyle(int style)
          Sets the style to be used for formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeFormatter

public TimeFormatter()
Constructs a TimeFormatter. This constructor uses the system default style for time display.

Since:
v4r2m0

TimeFormatter

public TimeFormatter(int style)
Constructs a TimeFormatter with the specified style for time display. If the style is not valid, an IllegalArgumentException is thrown.

Parameters:
style - a valid DateFormat style.
Since:
v4r5m0
Method Detail

parse

public Object parse(String source)
             throws IllegalUserDataException
Parses a string to produce a Date object. All styles are tried for parsing. If no style succeeds, then an IllegalUserDataException is thrown.

Overrides:
parse in class DataFormatter
Parameters:
source - the string to be parsed
Returns:
the Date obtained by parsing the string
Throws:
IllegalUserDataException
Since:
v4r2m0

format

public String format(Date date)
Format a date based on the current style set for the Time Formatter.

Parameters:
date - a valid Date object.
Since:
v4r5m0

format

public String format(Object obj)
Format a date based on the current style set for the Time Formatter. Throws an IllegalArgumentException if the object is not an instance of Date.

Overrides:
format in class DataFormatter
Parameters:
obj - a valid Date object cast as an object.
Returns:
formatted string
Since:
v4r5m0

setStyle

public void setStyle(int style)
Sets the style to be used for formatting. If the style is not valid, an IllegalArgumentException is thrown.

Parameters:
style - a valid DateFormat style.
Since:
v4r5m0

getStyle

public int getStyle()
Gets the style to be used for formatting.

Returns:
a DateFormat style.
Since:
v4r5m0