public class SimpleTimestampFormat extends SimpleDateFormat
DateFormat.Field
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_TIMESTAMP_FORMAT
Default format of the
Timestamp object for sql. |
AM_PM_FIELD, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Constructor and Description |
---|
SimpleTimestampFormat(String pattern)
Constructs a
SimpleTimestampFormat using the given pattern and the default date format symbols for the
default locale. |
SimpleTimestampFormat(String pattern,
DateFormatSymbols formatSymbols)
Constructs a
|
SimpleTimestampFormat(String pattern,
Locale locale)
Constructs a
SimpleTimestampFormat using the given pattern and the default date format symbols for the
given locale. |
Modifier and Type | Method and Description |
---|---|
void |
applyLocalizedPattern(String pattern)
Applies the given localized pattern string to this date format.
|
void |
applyPattern(String pattern)
Applies the given pattern string to this date format.
|
StringBuffer |
format(Date timestamp,
StringBuffer toAppendTo,
FieldPosition pos)
Formats the given
Date or >Timestamp into a date/time string and appends the result to
the given StringBuffer . |
AttributedCharacterIterator |
formatToCharacterIterator(Object obj)
See
SimpleDateFormat description. |
Date |
parse(String source)
Parses text from the beginning of the given string to produce a date.
|
Date |
parse(String text,
ParsePosition pos)
Parses text from a string to produce a
Timestamp . |
Object |
parseObject(String source,
ParsePosition pos)
Parses text from a string to produce a
Date . |
void |
setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
Sets the date and time format symbols of this date format.
|
String |
toLocalizedPattern()
Returns a localized pattern string describing this date format.
|
String |
toPattern()
Returns a pattern string describing this date format.
|
clone, equals, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, setCalendar, setLenient, setNumberFormat, setTimeZone
format, parseObject
public static final String DEFAULT_TIMESTAMP_FORMAT
Timestamp
object for sql.public SimpleTimestampFormat(String pattern)
SimpleTimestampFormat
using the given pattern and the default date format symbols for the
default locale. Note: This constructor may not support all locales. For full coverage, use the factory
methods in the SimpleTimestampFormat
class.pattern
- the pattern describing the date and time formatNullPointerException
- if the given pattern is nullIllegalArgumentException
- if the given pattern is invalidpublic SimpleTimestampFormat(String pattern, Locale locale)
SimpleTimestampFormat
using the given pattern and the default date format symbols for the
given locale. Note: This constructor may not support all locales. For full coverage, use the factory methods
in the SimpleTimestampFormat
class.pattern
- the pattern describing the date and time formatlocale
- the locale whose date format symbols should be usedNullPointerException
- if the given pattern or locale is nullIllegalArgumentException
- if the given pattern is invalidpublic SimpleTimestampFormat(String pattern, DateFormatSymbols formatSymbols)
pattern
- the pattern describing the date and time formatformatSymbols
- the date format symbols to be used for formattingNullPointerException
- if the given pattern or formatSymbols is nullIllegalArgumentException
- if the given pattern is invalidpublic void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
setDateFormatSymbols
in class SimpleDateFormat
newFormatSymbols
- the new date and time format symbolsNullPointerException
- if the given newFormatSymbols is nullSimpleDateFormat.getDateFormatSymbols()
public StringBuffer format(Date timestamp, StringBuffer toAppendTo, FieldPosition pos)
Date
or >Timestamp
into a date/time string and appends the result to
the given StringBuffer
.format
in class SimpleDateFormat
timestamp
- the date-time value to be formatted into a date-time string.toAppendTo
- where the new date-time text is to be appended.pos
- the formatting position. On input: an alignment field, if desired. On output: the offsets of the
alignment field.NullPointerException
- if the given timestamp
is null
.public AttributedCharacterIterator formatToCharacterIterator(Object obj)
SimpleDateFormat
description. This is dummy method to deprecate using parent implementation for
Timestamp
until it is not fully implemented.formatToCharacterIterator
in class SimpleDateFormat
public Date parse(String text, ParsePosition pos)
Timestamp
.
The method attempts to parse text starting at the index given by pos
. If parsing succeeds, then the
index of pos
is updated to the index after the last character used (parsing does not necessarily use
all characters up to the end of the string), and the parsed date is returned. The updated pos
can be
used to indicate the starting point for the next call to this method. If an error occurs, then the index of
pos
is not changed, the error index of pos
is set to the index of the character where the
error occurred, and null is returned.
This parsing operation uses the calendar
to produce a Date
. All of the
calendar
's date-time fields are cleared before parsing, and the
calendar
's default values of the date-time fields are used for any missing date-time information. For
example, the year value of the parsed Date
is 1970 with GregorianCalendar
if no year
value is given from the parsing operation. The TimeZone
value may be overwritten, depending on the given
pattern and the time zone value in text
. Any TimeZone
value that has previously been set by a call
to setTimeZone
may need to be restored for further operations.
parse
in class SimpleDateFormat
text
- A String
, part of which should be parsed.pos
- A ParsePosition
object with index and error index information as described above.Date
parsed from the string. In case of error, returns null.NullPointerException
- if text
or pos
is null.public String toPattern()
toPattern
in class SimpleDateFormat
public String toLocalizedPattern()
toLocalizedPattern
in class SimpleDateFormat
public void applyPattern(String pattern)
applyPattern
in class SimpleDateFormat
pattern
- the new date and time pattern for this date formatNullPointerException
- if the given pattern is nullIllegalArgumentException
- if the given pattern is invalidpublic void applyLocalizedPattern(String pattern)
applyLocalizedPattern
in class SimpleDateFormat
pattern
- a String to be mapped to the new date and time format pattern for this formatNullPointerException
- if the given pattern is nullIllegalArgumentException
- if the given pattern is invalidpublic Date parse(String source) throws ParseException
parse(String, java.text.ParsePosition)
method for more information on date parsing.parse
in class DateFormat
source
- A String
whose beginning should be parsed.Date
parsed from the string.ParseException
- if the beginning of the specified string cannot be parsed.public Object parseObject(String source, ParsePosition pos)
Date
.
The method attempts to parse text starting at the index given by pos
. If parsing succeeds, then the
index of pos
is updated to the index after the last character used (parsing does not necessarily use
all characters up to the end of the string), and the parsed date is returned. The updated pos
can be
used to indicate the starting point for the next call to this method. If an error occurs, then the index of
pos
is not changed, the error index of pos
is set to the index of the character where the
error occurred, and null is returned.
See the parse(String, java.text.ParsePosition)
method for more information on date parsing.parseObject
in class DateFormat
source
- A String
, part of which should be parsed.pos
- A ParsePosition
object with index and error index information as described above.Date
parsed from the string. In case of error, returns null.NullPointerException
- if pos
is null.