Class OraDateFormat

  • All Implemented Interfaces:
    Serializable, Cloneable
    Direct Known Subclasses:
    OraSimpleDateFormat

    public abstract class OraDateFormat
    extends Format
    The OraDateFormat class is an abstract class to do locale-sensitive formatting and parsing between date/time and string. It supports Oracle date/time formatting behavior.
    See Also:
    OraSimpleDateFormat, Serialized Form
    • Field Detail

      • ERA_FIELD

        public static final int ERA_FIELD
        Constant for ERA_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • YEAR_FIELD

        public static final int YEAR_FIELD
        Constant for YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • MONTH_FIELD

        public static final int MONTH_FIELD
        Constant for MONTH_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • DATE_FIELD

        public static final int DATE_FIELD
        Constant for DATE_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • HOUR_OF_DAY_FIELD

        public static final int HOUR_OF_DAY_FIELD
        Constant for HOUR_OF_DAY_FIELD alignment. Used to specify the field position for formatting. The HOUR_OF_DAY_FIELD is used for zero-base, 24-hour clock (0 ~ 23).
        See Also:
        Constant Field Values
      • MINUTE_FIELD

        public static final int MINUTE_FIELD
        Constant for MINUTE_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • SECOND_FIELD

        public static final int SECOND_FIELD
        Constant for SECOND_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • MILLISECOND_FIELD

        public static final int MILLISECOND_FIELD
        Constant for MILLISECOND_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • DAY_OF_WEEK_FIELD

        public static final int DAY_OF_WEEK_FIELD
        Constant for DAY_OF_WEEK_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • DAY_OF_YEAR_FIELD

        public static final int DAY_OF_YEAR_FIELD
        Constant for DAY_OF_YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • WEEK_OF_YEAR_FIELD

        public static final int WEEK_OF_YEAR_FIELD
        Constant for WEEK_OF_YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • WEEK_OF_MONTH_FIELD

        public static final int WEEK_OF_MONTH_FIELD
        Constant for WEEK_OF_MONTH_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • AM_PM_FIELD

        public static final int AM_PM_FIELD
        Constant for AM_PM_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • HOUR_FIELD

        public static final int HOUR_FIELD
        Constant for HOUR_FIELD alignment. Used to specify the field position for formatting. The HOUR_FIELD is used for one-base, 12-hour clock (1 ~ 12).
        See Also:
        Constant Field Values
      • TIMEZONE_FIELD

        public static final int TIMEZONE_FIELD
        Constant for TIMEZONE_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • ALL_FIELD

        public static final int ALL_FIELD
        Constant for ALL_FIELD alignment. Used to specify the field position for formatting. The ALL_FIELD is used to indicate all fields specified in a format pattern.
        See Also:
        Constant Field Values
      • CENTRY_FIELD

        public static final int CENTRY_FIELD
        Constant for CENTRY_FIELD alignment. Used to specify the field position for formatting. Centry is one greater than the first two digits of a four-digit year.
        See Also:
        Constant Field Values
      • JULIAN_DAY_FIELD

        public static final int JULIAN_DAY_FIELD
        Constant for JULIAN_DAY_FIELD alignment. Used to specify the field position for formatting. The Julian day is number of days since January 1, 4712 BC.
        See Also:
        Constant Field Values
      • QUARTER_OF_YEAR_FIELD

        public static final int QUARTER_OF_YEAR_FIELD
        Constant for QUARTER_OF_YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • SECONDS_FIELD

        public static final int SECONDS_FIELD
        Constant for SECONDS_FIELD alignment. Used to specify the field position for formatting. The SECONDS_FIELD is for number of seconds past midnight.
        See Also:
        Constant Field Values
      • TEXT_FIELD

        public static final int TEXT_FIELD
        Constant for TEXT_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • ISO_YEAR_FIELD

        public static final int ISO_YEAR_FIELD
        Constant for ISO_YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • ISO_WEEK_OF_YEAR_FIELD

        public static final int ISO_WEEK_OF_YEAR_FIELD
        Constant for ISO_WEEK_OF_YEAR_FIELD alignment. Used to specify the field position for formatting.
        See Also:
        Constant Field Values
      • SHORT

        public static final int SHORT
        Constant for date/time SHORT format style.
        See Also:
        Constant Field Values
      • LONG

        public static final int LONG
        Constant for date LONG format style.
        See Also:
        Constant Field Values
      • DEFAULT

        public static final int DEFAULT
        Constant for DEFAULT format style. For date, it is equivalent to Oracle server default date format. For time, it is equivalent to the time SHORT format style.
        See Also:
        Constant Field Values
      • calendar

        protected Calendar calendar
        The calendar that this OraDateFormat object uses to calculate the date/time field values. Subclasses should initialize the calendar object accordingly based on the locale associated with this OraDateFormat object.
    • Constructor Detail

      • OraDateFormat

        public OraDateFormat()
    • Method Detail

      • getDateInstance

        public static final OraDateFormat getDateInstance()
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getDateInstance(int, Locale)
        Returns a date formatter that uses the default date formatting style for the default locale.
        Returns:
        a date formatter
      • getDateInstance

        public static final OraDateFormat getDateInstance​(int style)
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getDateInstance(int, Locale)
        Returns a date formatter that uses the given date formatting style for the default locale.
        Parameters:
        style - the given date formatting style; options are SHORT, LONG or DEFAULT
        Returns:
        a date formatter
      • getDateInstance

        public static final OraDateFormat getDateInstance​(int style,
                                                          Locale locale)
        Returns a date formatter that uses the given date formatting style for the given locale.
        Parameters:
        style - the given date formatting style; options are SHORT, LONG or DEFAULT
        locale - the given locale
        Returns:
        a date formatter
      • getDateInstance

        public static final OraDateFormat getDateInstance​(int style,
                                                          OraLocaleInfo localeInfo)
        Returns a date formatter that uses the given date formatting style for the given OraLocaleInfo object.
        Parameters:
        style - the given date formatting style; options are SHORT, LONG or DEFAULT
        localeInfo - the given OraLocaleInfo object
        Returns:
        a date formatter
        Throws:
        IllegalArgumentException - if the given date formatting style is invalid
      • getDateTimeInstance

        public static final OraDateFormat getDateTimeInstance()
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getDateTimeInstance(int, Locale)
        Returns a date/time formatter that uses the default date/time formatting style for the default locale.
        Returns:
        a date/time formatter
      • getDateTimeInstance

        public static final OraDateFormat getDateTimeInstance​(int dateStyle)
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getDateTimeInstance(int, Locale)
        Returns a date/time formatter that uses the given date formatting style and the default time formatting style for the default locale.
        Parameters:
        dateStyle - the given date formatting style; options are SHORT, LONG or DEFAULT
        Returns:
        a date/time formatter
      • getDateTimeInstance

        public static final OraDateFormat getDateTimeInstance​(int dateStyle,
                                                              Locale locale)
        Returns a date/time formatter that uses the given date formatting style and the default time formatting style for the given locale.
        Parameters:
        dateStyle - the given date formatting style; options are SHORT, LONG or DEFAULT
        locale - the given locale
        Returns:
        a date/time formatter
      • getDateTimeInstance

        public static final OraDateFormat getDateTimeInstance​(int dateStyle,
                                                              OraLocaleInfo localeInfo)
        Returns a date/time formatter that uses the given date formatting style and the default time formatting style for the given OraLocaleInfo object.
        Parameters:
        dateStyle - the given date formatting style; options are SHORT, LONG or DEFAULT
        localeInfo - the given OraLocaleInfo object
        Returns:
        a date/time formatter
        Throws:
        IllegalArgumentException - if the given date formatting style is invalid
      • getInstance

        public static final OraDateFormat getInstance()
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getDateTimeInstance(int, Locale)
        Returns a date/time formatter that uses the default date/time formatting style for the default locale.
        Returns:
        a date/time formatter
      • getTimeInstance

        public static final OraDateFormat getTimeInstance()
        Deprecated.
        As of Oracle Database 10g Release 2 (10.2), replaced by getTimeInstance(Locale)
        Returns a time formatter that uses the default time formatting style for the default locale.
        Returns:
        a time formatter
      • getTimeInstance

        public static final OraDateFormat getTimeInstance​(Locale locale)
        Returns a time formatter for the given locale.
        Parameters:
        locale - the given locale
        Returns:
        a time formatter
      • getTimeInstance

        public static final OraDateFormat getTimeInstance​(OraLocaleInfo localeInfo)
        Returns a time formatter for the given OraLocaleInfo object.
        Parameters:
        localeInfo - the given OraLocaleInfo object
        Returns:
        a time formatter
      • format

        public final String format​(Date date)
        Formats a Date object into a date/time string.
        Parameters:
        date - the date/time object to be formatted into a date/time string
        Returns:
        the formatted date/time string
      • format

        public abstract StringBuffer format​(Date date,
                                            StringBuffer toAppendTo,
                                            FieldPosition fieldPosition)
        Formats a Date object into a date/time string. Sets field position if it is needed.
        Parameters:
        date - the date/time object to be formatted into a date/time string.
        toAppendTo - the string buffer to be appended with the formatted date/time string.
        fieldPosition - to be used to get offsets of a given field in the returned string buffer. On input, the alignment field of which the offsets are to be returned. On output, the offsets of the alignment field in the returned string buffer.
        Returns:
        the string buffer appended with the formatted date/time string
      • format

        public final StringBuffer format​(Object obj,
                                         StringBuffer toAppendTo,
                                         FieldPosition fieldPosition)
        Formats an object into a date/time string. Sets field position if it is needed.
        Specified by:
        format in class Format
        Parameters:
        obj - the object to be formatted into a date/time string. It must be an instance of Date or Number class.
        toAppendTo - the string buffer to be appended with the formatted date/time string.
        fieldPosition - to be used to get offsets of a given field in the returned string buffer. On input, the alignment field of which the offsets are to be returned. On output, the offsets of the alignment field in the returned string buffer.
        Returns:
        the string buffer appended with the formatted date/time string
        Throws:
        IllegalArgumentException - if the given object is neither an instance of Date class nor an instance of Number class
      • parse

        public Date parse​(String text)
                   throws ParseException
        Parses a date/time string into a date.
        Parameters:
        text - the date/time string to be parsed
        Returns:
        a Date object corresponding to the date/time string
        Throws:
        ParseException - if the format pattern associated with this formatter is not valid for parsing or the given date/time string cannot be parsed into a Date object
      • parse

        public abstract Date parse​(String text,
                                   ParsePosition pos)
        Parses a date/time string into a date, starting from the given parse position.
        Parameters:
        text - the date/time string.
        pos - indicates where to start the parsing on input. On output, returns where the parse ends if parsing succeeds, or the start index if it fails.
        Returns:
        a Date object
      • getDefaultDateFormatPattern

        public static String getDefaultDateFormatPattern​(int style,
                                                         Locale locale)
        Returns the default date format pattern for the given date formatting style and the given locale.
        Parameters:
        style - the given date formatting style
        locale - the given locale
        Returns:
        the default date format pattern
      • getDefaultDateFormatPattern

        public static String getDefaultDateFormatPattern​(int style,
                                                         OraLocaleInfo localeInfo)
        Returns the default date format pattern for the given date formatting style and the given OraLocaleInfo object.
        Parameters:
        style - the given date formatting style
        localeInfo - the given OraLocaleInfo object
        Returns:
        the default date format pattern
      • getDefaultDateTimeFormatPattern

        public static String getDefaultDateTimeFormatPattern​(int dateStyle,
                                                             Locale locale)
        Returns the default date/time format pattern for the given date formatting style and the given locale.
        Parameters:
        dateStyle - the given date formatting style
        locale - the given locale
        Returns:
        the default date/time format pattern
      • getDefaultDateTimeFormatPattern

        public static String getDefaultDateTimeFormatPattern​(int dateStyle,
                                                             OraLocaleInfo localeInfo)
        Returns the default date/time format pattern for the given date formatting style and the given OraLocaleInfo object.
        Parameters:
        dateStyle - the given date formatting style
        localeInfo - the given OraLocaleInfo object
        Returns:
        the default date/time format pattern
      • getDefaultTimeFormatPattern

        public static String getDefaultTimeFormatPattern​(Locale locale)
        Returns the default time format pattern for the given locale.
        Parameters:
        locale - the given locale
        Returns:
        the default time format pattern
      • getDefaultTimeFormatPattern

        public static String getDefaultTimeFormatPattern​(OraLocaleInfo localeInfo)
        Returns the default time format pattern for the given OraLocaleInfo object.
        Parameters:
        localeInfo - the given OraLocaleInfo object
        Returns:
        the default time format pattern
      • getCalendar

        public Calendar getCalendar()
        Returns the calendar associated with this date/time formatter.
        Returns:
        the Calendar object associated with this formatter
      • setCalendar

        public void setCalendar​(Calendar calendar)
        Sets the given calendar to be used by this date/time formatter.
        Parameters:
        calendar - the given Calendar object to be used by this formatter
      • getTimeZone

        public TimeZone getTimeZone()
        Returns the time zone associated with the calendar of this formatter.
        Returns:
        the TimeZone object associated with the calendar of this formatter
      • setTimeZone

        public void setTimeZone​(TimeZone timezone)
        Sets the given time zone to be used by the calendar of this formatter.
        Parameters:
        timezone - the given TimeZone object to be used by the calendar of this formatter
      • clone

        public Object clone()
        Overrides the clone method.
        Overrides:
        clone in class Format
        Returns:
        a cloned object
      • equals

        public boolean equals​(Object obj)
        Overrides the equals method.
        Overrides:
        equals in class Object
        Parameters:
        obj - an object to be compared
        Returns:
        true if two objects are identical, otherwise false