java.text.SimpleDateFormat .
To obtain a FastDatePrinter, use FastDateFormat#getInstance(String, TimeZone, Locale)
or another variation of the factory methods of FastDateFormat.
Since FastDatePrinter is thread safe, you can use a static member instance:
private static final DatePrinter DATE_PRINTER = FastDateFormat.getInstance("yyyy-MM-dd");
This class can be used as a direct replacement to
SimpleDateFormat in most formatting 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.
Only formatting is supported by this class, but all patterns are compatible with SimpleDateFormat (except time zones and some year patterns - see below).
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.
Starting with JDK7, ISO 8601 support was added using the pattern 'X'.
To maintain compatibility, 'ZZ' will continue to be supported, but using
one of the 'X' formats is recommended.
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. FastDatePrinter implements the behavior of Java 7.
FastDateParser
| Modifier and Type | Class and Description |
|---|---|
| private static class | FastDatePrinter.
Inner class to output a constant single character. |
| private static class | FastDatePrinter.
Inner class to output the numeric day in week. |
| private static class | FastDatePrinter.
Inner class to output a time zone as a number |
| private static interface | FastDatePrinter.
Inner class defining a numeric rule. |
| private static class | FastDatePrinter.
Inner class to output a padded number. |
| private static interface | FastDatePrinter.
Inner class defining a rule. |
| private static class | FastDatePrinter.
Inner class to output a constant string. |
| private static class | FastDatePrinter.
Inner class to output one of a set of values. |
| private static class | FastDatePrinter.
Inner class that acts as a compound key for time zone names. |
| private static class | FastDatePrinter.
Inner class to output a time zone name. |
| private static class | FastDatePrinter.
Inner class to output a time zone as a number |
| private static class | FastDatePrinter.
Inner class to output the twelve hour field. |
| private static class | FastDatePrinter.
Inner class to output the twenty four hour field. |
| private static class | FastDatePrinter.
Inner class to output a two digit month. |
| private static class | FastDatePrinter.
Inner class to output a two digit number. |
| private static class | FastDatePrinter.
Inner class to output a two digit year. |
| private static class | FastDatePrinter.
Inner class to output an unpadded month. |
| private static class | FastDatePrinter.
Inner class to output an unpadded number. |
| private static class | FastDatePrinter.
Inner class to output the numeric day in week. |
| Modifier and Type | Field and Description |
|---|---|
| private static final FastDatePrinter. | EMPTY_RULE_ARRAY
Empty array. |
| public static final int | FULL
FULL locale dependent date or time style. |
| private final Locale | locale
The locale. |
| public static final int | LONG
LONG locale dependent date or time style. |
| private static final int | |
| private transient int | maxLengthEstimate
The estimated maximum length. |
| public static final int | MEDIUM
MEDIUM locale dependent date or time style. |
| private final String | pattern
The pattern. |
| private transient FastDatePrinter. | rules
The parsed rules. |
| private static final long | serialVersionUID
Required for serialization support. |
| public static final int | SHORT
SHORT locale dependent date or time style. |
| private final TimeZone | timeZone
The time zone. |
| private static final ConcurrentMap |
| Access | Constructor and Description |
|---|---|
| protected | FastDatePrinter(final String
java. compatible pattern.non-null time zone to use. timeZone, final Locale non-null locale to use. locale)Constructs a new FastDatePrinter. |
| Modifier and Type | Method and Description |
|---|---|
| private static void | appendDigits(final Appendable
the buffer to append to. buffer, final int the value to append digits from. value)Appends two digits to the given buffer. |
| private static void | appendFullDigits(final Appendable
the buffer to append to. buffer, int the value to append digits from. value, int Minimum field width. minFieldWidth)Appends all digits to the given buffer. |
| private < the Appendable class type, usually StringBuilder or StringBuffer. B extends Appendable> B | Returns: the specified string buffer.the calendar to format. calendar, final B the buffer to format into. buf)Performs the formatting by applying the rules to the specified calendar. |
| protected StringBuffer | Returns: the specified string buffer.the calendar to format. calendar, final StringBuffer the buffer to format into. buf)
Deprecated
Use
format(Calendar) or format(Calendar, Appendable)
Performs the formatting by applying the rules to the specified calendar. |
| private String | Returns: a String representation of the given Calendar.the Calendar to apply the rules to. c)Creates a String representation of the given Calendar by applying the rules of this printer to it. |
| 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 | format(final Calendar calendar)
Implements org. Formats a |
| public <B extends Appendable> B | format(final Calendar calendar, final B buf)
Implements org. Formats a |
| public StringBuffer | format(final Calendar calendar, final StringBuffer buf)
Implements org. Formats a |
| public String | format(final Date date)
Implements org. Formats a |
| public <B extends Appendable> B | format(final Date date, final B buf)
Implements org. Formats a |
| public StringBuffer | format(final Date date, final StringBuffer buf)
Implements org. Formats a |
| public String | format(final long millis)
Implements org. Formats a millisecond |
| public <B extends Appendable> B | format(final long millis, final B buf)
Implements org. Formats a millisecond |
| public StringBuffer | format(final long millis, final StringBuffer buf)
Implements org. Formats a millisecond |
| pack-priv String | |
| public StringBuffer | Returns: the buffer passed in.the object to format. obj, final StringBuffer the buffer to append to. toAppendTo, final FieldPosition the position; ignored. pos)Implements org.
Deprecated
Use {
format(Date), {format(Calendar), {format(long).
|
| public Locale | getLocale()
Implements org. Gets the locale used by this printer. |
| public int | Returns: the maximum formatted length.Gets an estimate for the maximum string length that the formatter will produce. |
| public String | getPattern()
Implements org. Gets the pattern used by this printer. |
| public TimeZone | getTimeZone()
Implements org. Gets the time zone used by this printer. |
| pack-priv static String | Returns: the textual name of the time zone.the zone to query. tz, final boolean true if daylight savings. daylight, final int the style to use style, final Locale TimeZone#LONG or TimeZone#SHORT.the locale to use. locale)Gets the time zone display name, using a cache for performance. |
| public int | Returns: a hash code compatible with equals.Overrides java. Returns a hash code compatible with equals. |
| private void | |
| private Calendar | |
| protected List | |
| protected String | Returns: parsed token.the pattern. pattern, final int[] index references. indexRef)Performs the parsing of tokens. |
| private void | readObject(final ObjectInputStream
ObjectInputStream from which the object is being deserialized. in)Create the object after serialization. |
| protected FastDatePrinter. | Returns: a new rule with the correct padding.the field to get a rule for. field, final int the padding required. padding)Gets an appropriate rule for the padding required. |
| public String | Returns: a debugging string.Overrides java. Gets a debugging string version of this formatter. |