java.text.SimpleDateFormat .
To obtain a proxy to a FastDateParser, use FastDateFormat#getInstance(String, TimeZone, Locale) or another variation of the factory methods of
FastDateFormat.
Since FastDateParser is thread safe, you can use a static member instance:
private static final DateParser DATE_PARSER = FastDateFormat.getInstance("yyyy-MM-dd");
This class can be used as a direct replacement for SimpleDateFormat in most 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 has closed the
bug/RFE.
Only parsing is supported by this class, but all patterns are compatible with SimpleDateFormat.
The class operates in lenient mode, so for example a time of 90 minutes is treated as 1 hour 30 minutes.
Timing tests indicate this class is as about as fast as SimpleDateFormat in single thread applications and about 25% faster in multi-thread applications.
FastDatePrinter
| Modifier and Type | Class and Description |
|---|---|
| private static class | FastDateParser.
A strategy that handles a text field in the parsing pattern |
| private static class | FastDateParser.
A strategy that copies the static or quoted field in the parsing pattern |
| private static class | |
| private static class | FastDateParser.
A strategy that handles a number field in the parsing pattern |
| private abstract static class | FastDateParser.
A strategy to parse a single field from the parsing pattern |
| private abstract static class | FastDateParser.
A strategy to parse a single field from the parsing pattern |
| private static class | FastDateParser.
Holds strategy and field width |
| private class | FastDateParser.
Parse format into Strategies |
| pack-priv static class | FastDateParser.
A strategy that handles a time zone field in the parsing pattern |
| Modifier and Type | Field and Description |
|---|---|
| private static final FastDateParser. | |
| private static final ConcurrentMap | |
| private final int | century
Century from Date. |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| pack-priv static final Locale | |
| private static final FastDateParser. | |
| private final Locale | locale
Input Locale. |
| private static final Comparator | LONGER_FIRST_LOWERCASE
comparator used to sort regex alternatives. |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private static final FastDateParser. | |
| private final String | pattern
Input pattern. |
| private transient List | patterns
Initialized from Calendar. |
| private static final FastDateParser. | |
| private static final long | serialVersionUID
Required for serialization support. |
| private final int | startYear
Start year from Date. |
| private final TimeZone | timeZone
Input TimeZone. |
| private static final FastDateParser. | |
| private static final FastDateParser. |
| Access | Constructor and Description |
|---|---|
| protected | FastDateParser(final String
non-null pattern, final TimeZone java. compatible patternnon-null time zone to use timeZone, final Locale non-null locale locale)Constructs a new FastDateParser. |
| protected | FastDateParser(final String
non-null pattern, final TimeZone java. compatible patternnon-null time zone to use timeZone, final Locale locale, null maps to the default Locale. locale, final Date The start of the century for 2 digit year parsing centuryStart)Constructs a new FastDateParser. |
| Modifier and Type | Method and Description |
|---|---|
| private int | Returns: A value between centuryStart(inclusive) to centuryStart+100(exclusive)The year to adjust twoDigitYear)Adjusts dates to be within appropriate century |
| private static Map | Returns: The map of string display names to field valuesThe calendar to obtain the short and long values calendar, final Locale The locale of display names locale, final int The field of interest field, final StringBuilder The regular expression to build regex)Gets the short and long values displayed for a field |
| pack-priv static void | |
| public boolean | Returns: trueif equal to this instancethe object to compare to obj)Overrides java. Compares another object for equality with this object. |
| private static ConcurrentMap | Returns: a cache of Locale to StrategyThe Calendar field field)Gets a cache of Strategies for a particular field |
| public Locale | getLocale()
Implements org. Gets the locale used by this parser. |
| private FastDateParser. | Returns: a TextStrategy for the field and LocaleThe Calendar field field, final Calendar The calendar to obtain the short and long values definingCalendar)Constructs a Strategy that parses a Text field |
| public String | getPattern()
Implements org. Gets the pattern used by this parser. |
| private FastDateParser. | Returns: The Strategy that will handle parsing for the fieldA sub-sequence of the SimpleDateFormat pattern f, final int formatting width width, final Calendar The calendar to obtain the short and long values definingCalendar)Gets a Strategy given a field from a SimpleDateFormat pattern |
| public TimeZone | getTimeZone()
Implements org. Gets the time zone used by this parser. |
| public int | Returns: a hash code compatible with equalsOverrides java. Returns a hash code compatible with equals. |
| private void | init(final Calendar
the definingCalendar)java. instance used to initialize this FastDateParserInitializes derived fields from defining fields. |
| public Date | parse(final String source)
Implements org. Equivalent to DateFormat.parse(String). |
| public Date | parse(final String source, final ParsePosition pos)
Implements org. This implementation updates the ParsePosition if the parse succeeds. |
| public boolean | Returns: true, if source has been parsed (pos parsePosition is updated); otherwise false (and pos errorIndex is updated)The text to parse. source, final ParsePosition On input, the position in the source to start parsing, on output, updated position. pos, final Calendar The calendar into which to set parsed fields. calendar)Implements org. Parses a formatted date string according to the format. |
| public Object | parseObject(final String source)
Implements org. Parses text from a string to produce a Date. |
| public Object | parseObject(final String source, final ParsePosition pos)
Implements org. Parses a date/time string according to the given parse position. |
| private void | readObject(final ObjectInputStream
ObjectInputStream from which the object is being deserialized. in)Creates the object after serialization. |
| private static StringBuilder | |
| public String | Returns: a debugging stringOverrides java. Gets a string version of this formatter. |
| public String |