java.text.SimpleDateFormat .
To obtain an instance of FastDateFormat, use one of the static factory methods: getInstance(String, TimeZone, Locale),
getDateInstance(int, TimeZone, Locale), getTimeInstance(int, TimeZone, Locale), or getDateTimeInstance(int, int, TimeZone, Locale)
Since FastDateFormat is thread safe, you can use a static member instance:
private static final FastDateFormat DATE_FORMATTER = FastDateFormat.getDateTimeInstance(FastDateFormat.LONG, FastDateFormat.SHORT);
This class can be used as a direct replacement to SimpleDateFormat in most formatting and parsing situations. This class is especially useful in
multi-threaded server environments. SimpleDateFormat is not thread-safe in any JDK version, nor will it be as Sun have closed the bug/RFE.
All patterns are compatible with SimpleDateFormat (except time zones and some year patterns - see below).
Since 3.2, FastDateFormat supports parsing as well as printing.
Java 1.4 introduced a new pattern letter, 'Z', to represent time zones in RFC822 format (for example, +0800 or -1100). This pattern letter can
be used here (on all JDK versions).
In addition, the pattern 'ZZ' has been made to represent ISO 8601 extended format time zones (for example, +08:00 or -11:00). This introduces
a minor incompatibility with Java 1.4, but at a gain of useful functionality.
Javadoc cites for the year pattern: For formatting, if the number of pattern letters is 2, the year is truncated to 2 digits; otherwise it is interpreted as a number. Starting with Java 1.7 a pattern of 'Y' or 'YYY' will be formatted as '2003', while it was '03' in former Java versions. FastDateFormat implements the behavior of Java 7.
| Modifier and Type | Field and Description |
|---|---|
| private static final AbstractFormatCache | |
| public static final int | FULL
FULL locale dependent date or time style. |
| public static final int | LONG
LONG locale dependent date or time style. |
| public static final int | MEDIUM
MEDIUM locale dependent date or time style. |
| private final FastDateParser | parser
Our fast parser. |
| private final FastDatePrinter | printer
Our fast printer. |
| private static final long | serialVersionUID
Required for serialization support.
|
| public static final int | SHORT
SHORT locale dependent date or time style. |
| Access | Constructor and Description |
|---|---|
| protected | FastDateFormat(final String
java. compatible pattern.non-null time zone to use. timeZone, final Locale non-null locale to use. locale)Constructs a new FastDateFormat. |
| protected | FastDateFormat(final String
java. compatible pattern.non-null time zone to use. timeZone, final Locale non-null locale to use. locale, final Date The start of the 100-year period to use as the "default century" for 2 digit year parsing. If centuryStart is null, defaults to now -
80 years. centuryStart)Constructs a new FastDateFormat. |
| Modifier and Type | Method and Description |
|---|---|
| protected StringBuffer | Returns: the specified string buffer.the calendar to format. calendar, final StringBuffer the buffer to format into. buf)
Deprecated
Use
format(Calendar, Appendable)
Performs the formatting by applying the rules to the specified calendar. |
| pack-priv static void | |
| public boolean | Returns: true if equal.the object to compare to. obj)Overrides java. Compares two objects for equality. |
| public String | Returns: the formatted string.the calendar to format. calendar)Implements org. Formats a |
| public <B extends Appendable> B | Returns: the specified string buffer.the calendar to format. calendar, final B the buffer to format into. buf)Implements org. Formats a |
| public StringBuffer | Returns: the specified string buffer.the calendar to format. calendar, final StringBuffer the buffer to format into. buf)Implements org.
Deprecated
Use {
format(Calendar, Appendable).
Formats a |
| public String | Returns: the formatted string.the date to format. date)Implements org. Formats a |
| public <B extends Appendable> B | Returns: the specified string buffer.the date to format. date, final B the buffer to format into. buf)Implements org. Formats a |
| public StringBuffer | Returns: the specified string buffer.the date to format. date, final StringBuffer the buffer to format into. buf)Implements org.
Deprecated
Use {
format(Date, Appendable).
Formats a |
| public String | Returns: the formatted string.the millisecond value to format. millis)Implements org. Formats a millisecond |
| public <B extends Appendable> B | Returns: the specified string buffer.the millisecond value to format. millis, final B the buffer to format into. buf)Implements org. Formats a millisecond |
| public StringBuffer | Returns: the specified string buffer.the millisecond value to format. millis, final StringBuffer the buffer to format into. buf)Implements org.
Deprecated
Use {
format(long, Appendable).
Formats a millisecond |
| public StringBuffer | Returns: the given buffer.the object to format. obj, final StringBuffer the buffer to append to. toAppendTo, final FieldPosition the position, ignored. pos)Implements abstract java. Implements org. |
| public static FastDateFormat | Returns: a localized standard date formatter.Gets a date formatter instance using the specified style in the default time zone and locale. |
| public static FastDateFormat | |
| public static FastDateFormat | |
| public static FastDateFormat | Returns: a localized standard date formatter.optional time zone, overrides time zone of formatted date. timeZone, final Locale optional locale, overrides system locale. locale)Gets a date formatter instance using the specified style, time zone and locale. |
| public static FastDateFormat | |
| public static FastDateFormat | Returns: a localized standard date/time formatter.optional locale, overrides system locale. locale)Gets a date/time formatter instance using the specified style and locale in the default time zone. |
| public static FastDateFormat | Returns: a localized standard date/time formatter.optional time zone, overrides time zone of formatted date. timeZone)Gets a date/time formatter instance using the specified style and time zone in the default locale. |
| public static FastDateFormat | Returns: a localized standard date/time formatter.optional time zone, overrides time zone of formatted date. timeZone, final Locale optional locale, overrides system locale. locale)Gets a date/time formatter instance using the specified style, time zone and locale. |
| public static FastDateFormat | Returns: a date/time formatter.Gets a formatter instance using the default pattern in the default locale. |
| public static FastDateFormat | Returns: a pattern based date/time formatter.java. compatible pattern.Gets a formatter instance using the specified pattern in the default locale and time zone. |
| public static FastDateFormat | Returns: a pattern based date/time formatter.java. compatible pattern.optional locale, overrides system locale. locale)Gets a formatter instance using the specified pattern and locale using the default time zone. |
| public static FastDateFormat | Returns: a pattern based date/time formatter.java. compatible pattern.optional time zone, overrides time zone of formatted date. timeZone)Gets a formatter instance using the specified pattern and time zone. |
| public static FastDateFormat | Returns: a pattern based date/time formatter.java. compatible pattern.optional time zone, overrides time zone of formatted date. timeZone, final Locale optional locale, overrides system locale. locale)Gets a formatter instance using the specified pattern, time zone and locale. |
| public Locale | Returns: the locale.Implements org. Gets the locale used by this formatter. |
| public int | Returns: the maximum formatted length.Gets an estimate for the maximum string length that the formatter will produce. |
| public String | Returns: the pattern,java. compatible.Implements org. Gets the pattern used by this formatter. |
| public static FastDateFormat | Returns: a localized standard time formatter.Gets a time formatter instance using the specified style in the default time zone and locale. |
| public static FastDateFormat | |
| public static FastDateFormat | |
| public static FastDateFormat | Returns: a localized standard time formatter.optional time zone, overrides time zone of formatted time. timeZone, final Locale optional locale, overrides system locale. locale)Gets a time formatter instance using the specified style, time zone and locale. |
| public TimeZone | Returns: the time zone.Implements org. Gets the time zone used by this formatter. |
| public int | Returns: a hash code compatible with equals.Overrides java. Returns a hash code compatible with equals. |
| public Date | parse(final String source)
Implements org. Equivalent to DateFormat.parse(String). |
| public Date | parse(final String source, final ParsePosition pos)
Implements org. Equivalent to DateFormat.parse(String, ParsePosition). |
| public boolean | parse(final String source, final ParsePosition pos, final Calendar calendar)
Implements org. Parses a formatted date string according to the format. |
| public Object | parseObject(final String source, final ParsePosition pos)
Implements abstract java. Implements org. Parses a date/time string according to the given parse position. |
| public String | Returns: a debug string.Overrides java. Gets a debugging string version of this formatter. |