Formats and parses dates according to a token-based string format. This class is fully localized.
An instance of this class is defined by its format, which is a string conforming to the following syntax:
- Some letters (a-z, A-Z) are tokens that represent date fields (the tokens are described below). All other
letters are reserved.
- Letters that are not part of tokens must lie between single quotation marks.
-
'' formats/parses a single quotation mark.
- All other characters are allowed and have no special meaning.
The following tokens are supported:
-
G — the era (BC/AD) (Text).
-
y — the year, either as the full year or
as the last two digits of the year (Year).
-
M — the month, either as a digit or as
the name (Month).
-
d — the day of the month (Number).
-
E — the day of the week (Text).
-
H — the hour of the day (0-23) (Number).
-
h — the hour of the day (1-12) (Number).
-
m — the minute of the hour (Number).
-
s — the second of the minute (Number).
-
S — the milliseconds of the second (Number).
-
a — AM/PM marker (Text).
-
z — the time zone formatted as
GMT-08:00
-
Z — the time zone formatted as
-0800
Each token has a type, which determines how it is formatted and parsed. The token types are:
-
Number
—
For formatting, the number of characters in the token is the minimum number of digits to display. Smaller
numbers are zero-padded on the left. For parsing, if the following token is non-numeric, any number of digits
is parsed. Otherwise, exactly the number of digits is parsed as characters in the token.
-
Text
—
For formatting, if the token is four characters or longer, the entire string is printed, otherwise a substring
equal in length to the length of the token is printed. For parsing, the best match at least one character long
is parsed.
-
Year
—
If the length of the token is 2, the token is formatted and parsed as the last two digits of a year between
80 years prior and 20 years subsequent to the current date. Otherwise, it is formatted and parsed as a Number.
-
Month
—
If the length of the token is 2 or shorter, the token is formatted and parsed as a Number. Otherwise, the
month is formatted and parsed as Text.
| Method Summary |
|---|
| String | Formats a date according to this date format. |
| static jsx3.util.DateFormat | Returns a date format localized for a particular locale. |
| static jsx3.util.DateFormat | Returns a date and time format localized for a particular locale. |
| String | Returns the format passed to the constructor. |
| jsx3.util.Locale | |
| static jsx3.util.DateFormat | Returns a time format localized for a particular locale. |
| int | Returns the timezone offset of this date format. |
| Date | Parses a string according to this date format and returns the resulting date. |
| void | |
| void | Sets the timezone offset of this date format. |
| String | Returns a string representation of this date format. |
Type for a full-length localized date or time format.
Type for a long localized date or time format.
Type for a medium-length localized date or time format.
Type for a short localized date or time format.
The instance initializer. Instances of this class are immutable.
Parameters:
strFormat – the date format.
objLocale – the locale with which to format and parse dates. If this parameter is not
provided the default system locale is used.
Throws:
See Also:
Formats a date according to this date format.
Parameters:
objDate – the date to format.
Returns:
the formatted date.
Returns a date format localized for a particular locale.
Parameters:
intType – SHORT, MEDIUM, LONG, or FULL
objLocale – the locale for which to return a format. If this parameter is not provided,
the default system locale is used.
Returns:
Returns a date and time format localized for a particular locale.
Parameters:
intDateType – SHORT, MEDIUM, LONG, or FULL
intTimeType – SHORT, MEDIUM, LONG, or FULL
objLocale – the locale for which to return a format. If this parameter is not provided,
the default system locale is used.
Returns:
Returns the format passed to the constructor.
Returns:
Returns a time format localized for a particular locale.
Parameters:
intType – SHORT, MEDIUM, LONG, or FULL
objLocale – the locale for which to return a format. If this parameter is not provided,
the default system locale is used.
Returns:
Returns the timezone offset of this date format. This is the difference between GMT and the local time of this
date format, in minutes. For example, Pacific Standard Time is -480 (-08h * 60). If the timezone offset has been
set explicitly with
setTimeZoneOffset(), that value is returned.
Since the timezone offset may change over the year for Daylight Savings Time, this method takes a
Date argument,
objDate. All dates are created with the timezone offset of the host
browser's timezone, adjusted for Daylight Savings Time. Therefore, if the timezone offset of this date format
has not been set explicitly, the timezone offset is determined from the
objDate parameter, or, if
that is not provided, from the current time.
Parameters:
objDate – the date for which to return the timezone offset.
Returns:
the timezone offset in minutes.
Parses a string according to this date format and returns the resulting date. If
strDate does
not conform to this date format, an exception is thrown.
The default date for the purposes of this method is 1-Jan-1970 12:00AM, local time. If any date fields
are omitted from this format, the date returned by this method will inherit those fields from the default date.
Parameters:
strDate – the string to parse.
Throws:
Returns:
the parsed date.
Sets the timezone offset of this date format. The default value is the value for the local time.
Parameters:
intMinutes – the timezone offset in minutes.
See Also:
Returns a string representation of this date format.
Returns:
Overrides:
Copyright © 2001-2007, TIBCO Software Inc.