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

java.lang.Object
  |
  +--com.ibm.as400.ui.framework.java.DataFormatter
        |
        +--com.ibm.as400.ui.framework.java.DateFormatter

public class DateFormatter
extends DataFormatter

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

Dates 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 date portions of the Date object returned from parsing are meaningful.

Since:
v4r2m0
See Also:
DataBean, IllegalUserDataException, DateFormat

Constructor Summary
DateFormatter()
          Constructs a DateFormatter.
DateFormatter(int style)
          Constructs a DateFormatter with the specified style for date display.
 
Method Summary
 java.lang.String format(java.util.Date date)
          Format a date based on the current style set for the Date Formatter.
 java.lang.String format(java.lang.Object obj)
          Format a date based on the current style set for the Date Formatter.
 int getStyle()
          Gets the style to be used for formatting.
 java.lang.Object parse(java.lang.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

DateFormatter

public DateFormatter()
Constructs a DateFormatter. This constructor uses the system default style for date display.
Since:
v4r2m0

DateFormatter

public DateFormatter(int style)
Constructs a DateFormatter with the specified style for date display. If the style is not valid, an IllegalArgumentException is thrown.
Parameters:
style - a valid DateFormat style.
Since:
v4r5m0
Method Detail

parse

public java.lang.Object parse(java.lang.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
Since:
v4r2m0

format

public java.lang.String format(java.util.Date date)
Format a date based on the current style set for the Date Formatter.
Parameters:
date - a valid Date object.
Since:
v4r5m0

format

public java.lang.String format(java.lang.Object obj)
Format a date based on the current style set for the Date 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.
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