Class SimpleTimestampFormat

    • Field Detail

      • DEFAULT_TIMESTAMP_FORMAT

        public static final String DEFAULT_TIMESTAMP_FORMAT
        Default format of the Timestamp object for sql.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SimpleTimestampFormat

        public SimpleTimestampFormat​(String pattern)
        Constructs a 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.
        Parameters:
        pattern - the pattern describing the date and time format
        Throws:
        NullPointerException - if the given pattern is null
        IllegalArgumentException - if the given pattern is invalid
      • SimpleTimestampFormat

        public SimpleTimestampFormat​(String pattern,
                                     Locale locale)
        Constructs a 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.
        Parameters:
        pattern - the pattern describing the date and time format
        locale - the locale whose date format symbols should be used
        Throws:
        NullPointerException - if the given pattern or locale is null
        IllegalArgumentException - if the given pattern is invalid
      • SimpleTimestampFormat

        public SimpleTimestampFormat​(String pattern,
                                     DateFormatSymbols formatSymbols)
        Constructs a using the given pattern and date format symbols.
        Parameters:
        pattern - the pattern describing the date and time format
        formatSymbols - the date format symbols to be used for formatting
        Throws:
        NullPointerException - if the given pattern or formatSymbols is null
        IllegalArgumentException - if the given pattern is invalid
    • Method Detail

      • format

        public 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.
        Overrides:
        format in class SimpleDateFormat
        Parameters:
        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.
        Returns:
        the formatted date-time string.
        Throws:
        NullPointerException - if the given timestamp is null.
      • parse

        public Date parse​(String text,
                          ParsePosition pos)
        Parses text from a string to produce a 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.

        Overrides:
        parse in class SimpleDateFormat
        Parameters:
        text - A String, part of which should be parsed.
        pos - A ParsePosition object with index and error index information as described above.
        Returns:
        A Date parsed from the string. In case of error, returns null.
        Throws:
        NullPointerException - if text or pos is null.
      • toPattern

        public String toPattern()
        Returns a pattern string describing this date format.
        Overrides:
        toPattern in class SimpleDateFormat
        Returns:
        a pattern string describing this date format.
      • toLocalizedPattern

        public String toLocalizedPattern()
        Returns a localized pattern string describing this date format.
        Overrides:
        toLocalizedPattern in class SimpleDateFormat
        Returns:
        a localized pattern string describing this date format.
      • parse

        public Date parse​(String source)
                   throws ParseException
        Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.

        See the parse(String, java.text.ParsePosition) method for more information on date parsing.

        Overrides:
        parse in class DateFormat
        Parameters:
        source - A String whose beginning should be parsed.
        Returns:
        A Date parsed from the string.
        Throws:
        ParseException - if the beginning of the specified string cannot be parsed.
      • parseObject

        public Object parseObject​(String source,
                                  ParsePosition pos)
        Parses text from a string to produce a 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.

        Overrides:
        parseObject in class DateFormat
        Parameters:
        source - A String, part of which should be parsed.
        pos - A ParsePosition object with index and error index information as described above.
        Returns:
        A Date parsed from the string. In case of error, returns null.
        Throws:
        NullPointerException - if pos is null.