public class DateFormatter extends Object
Directive | Meaning |
---|---|
%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. |
Modifier and Type | Field and Description |
---|---|
private SimpleDateFormat |
fmt |
private String |
pattern |
Constructor and Description |
---|
DateFormatter(String pattern)
Construct a new
DateFormatter . |
Modifier and Type | Method and Description |
---|---|
private String |
constructPattern(String text) |
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. |
private SimpleDateFormat fmt
public DateFormatter(String pattern) throws IllegalArgumentException
DateFormatter
. See the table of formatting
directives above.pattern
- The pattern to be used by this formatter.IllegalArgumentException
- If the pattern contains
unrecognized formatting directives.public Date parse(String text) throws ParseException
Date
object.text
- The text to parse.Date
object corresponding to the parsed date.ParseException
- If a parsing error occurred.format(java.util.Calendar)
public String format(Calendar date)
Calendar
object. The date is formatted according
to the pattern specified in this object's constructor.date
- The Date
to format.parse(java.lang.String)
public String format()
parse(java.lang.String)
public String format(Date date)
Date
object. The date is formatted
according to the pattern specified in this object's constructor.date
- The Date
to format.parse(java.lang.String)
private String constructPattern(String text) throws IllegalArgumentException
IllegalArgumentException
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses