kiwi.text
Class DateFormatter

java.lang.Object
  |
  +--kiwi.text.DateFormatter

public class DateFormatter
extends Object

This class represents a high-level date parser/formatter that is almost fully format-string-compatible with the UNIX strftime(3) function. Date formats are specified by formatting directives; these directives are enumerated in the table below:

DirectiveMeaning
%a Abbreviated weekday name (3 characters).
%A Full weekday name.
%b Abbreviated month name (3 characters).
%B Full month name.
%d Day of month (01-31).
%e Day of month (no leading zero).
%H 24-hour clock hour (00-23).
%I 12-hour clock hour (01-12).
%j Day in year (001-366).
%m Month in year (01-12).
%M Minutes (00-59).
%N Era name.
%p AM/PM character.
%r Equivalent to %I:%M:%S %p.
%R Equivalent to %H:%M.
%s Milliseconds (000-999).
%S Seconds (00-59).
%t Tab character.
%T Equivalent to %H:%M%:S.
%u Equivalent to %a.
%U Week of year.
%y Year (2 digits).
%Y Year (4 digits).
%Z Time zone name (4 characters).
%% The % character.
. : / - , ; These characters are interpreted literally.

Version:
1.0.1 (10/98)
Author:
Mark Lindner, PING Software Group

Constructor Summary
DateFormatter(String pattern)
          Construct a new DateFormatter.
 
Method Summary
 String format()
          Format the current date.
 String format(Calendar date)
          Format a Calendar object.
 String format(Date date)
          Format a date from a Date object.
 Date parse(String text)
          Parse a date, returning a Date object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateFormatter

public DateFormatter(String pattern)
              throws IllegalArgumentException
Construct a new DateFormatter. See the table of formatting directives above.
Parameters:
pattern - The pattern to be used by this formatter.
Throws:
IllegalArgumentException - If the pattern contains unrecognized formatting directives.
Method Detail

parse

public Date parse(String text)
           throws ParseException
Parse a date, returning a Date object.
Parameters:
text - The text to parse.
Returns:
A Date object corresponding to the parsed date.
Throws:
ParseException - If a parsing error occurred.
See Also:
format(java.util.Calendar)

format

public String format(Calendar date)
Format a Calendar object. The date is formatted according to the pattern specified in this object's constructor.
Parameters:
date - The Date to format.
Returns:
The date formatted as a string.
See Also:
parse(java.lang.String)

format

public String format()
Format the current date. The date is formatted according to the pattern specified in this object's constructor.
Returns:
The date formatted as a string.
See Also:
parse(java.lang.String)

format

public String format(Date date)
Format a date from a Date object. The date is formatted according to the pattern specified in this object's constructor.
Parameters:
date - The Date to format.
Returns:
The date formatted as a string.
See Also:
parse(java.lang.String)