Class DateTimeFormatting


  • public class DateTimeFormatting
    extends Object
    Describes the formatting of a string representing a date/time value. Primarily, this provides the formatting pattern used for laying out the various fields. Patterns use the syntax of the Joda time library which uses a similar format to that described in SimpleDateFormat. Most specifiers compatible with the JDK will be compatible with Joda time, the notable exceptions being:
    • The 'W' (week in month) specifier is not supported.
    • The 'F' (day of week as number) specifier is replaced with 'e'.

    Additional properties related to the parsing of values are also provided:

    • Whether parsing is lenient. That is, whether values which are syntactically correct, such as 2/30/1999, are parsed without error. If allowed, values are adjusted to valid ones; in this case, 3/2/1999 - two (30-28) days after 2/28/1999. By default, parsing is strict.
    • The pivot year for two-digit year values. Dates are assumed to be within the 100-year period starting on January 1st 50 years prior to the pivot year. By default, 2000 is the pivot year, meaning two-digit years represent values between 1950 and 2049.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_PIVOT
      The default pivot year used for two-digit year values, 2000.
    • Constructor Summary

      Constructors 
      Constructor Description
      DateTimeFormatting​(String pattern)
      Defines a format using the specified pattern.
      DateTimeFormatting​(String pattern, boolean lenient)
      Defines a format using the specified pattern and parsing leniency.
      DateTimeFormatting​(String pattern, int pivotYear)
      Defines a format using the specified pattern and pivot year.
    • Field Detail

      • DEFAULT_PIVOT

        public static final int DEFAULT_PIVOT
        The default pivot year used for two-digit year values, 2000.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DateTimeFormatting

        public DateTimeFormatting​(String pattern)
        Defines a format using the specified pattern. Parsing will be strict, rejecting syntactically correct but otherwise invalid values such as 4/31/1999 or 13:61:00. Two digit years will be assumed to be between 1950 and 2049.
        Parameters:
        pattern - the text format to use
      • DateTimeFormatting

        public DateTimeFormatting​(String pattern,
                                  boolean lenient)
        Defines a format using the specified pattern and parsing leniency. Two digit years will be assumed to be between 1950 and 2049.
        Parameters:
        pattern - the text format to use
        lenient - indicates whether parsing should be lenient.
      • DateTimeFormatting

        public DateTimeFormatting​(String pattern,
                                  int pivotYear)
        Defines a format using the specified pattern and pivot year. Parsing will be strict, rejecting syntactically correct but otherwise invalid values such as 4/31/1999 or 13:61:00.
        Parameters:
        pattern - the text format to use
        pivotYear - the year in the middle of the 100-year period used by two-digit year values
    • Method Detail

      • setPattern

        public void setPattern​(String pattern)
        Specifies the format pattern to use when parsing or formatting date/time values.
        Parameters:
        pattern - the format pattern to use
      • getPattern

        public String getPattern()
        Gets the format pattern used for parsing and formatting date/time values.
        Returns:
        the format pattern to use
      • setLenient

        public void setLenient​(boolean lenient)
        Specifies whether parsing of values should be lenient. That is, whether to parse values which match the formatting pattern but do not represent real date/time values, such as 4/31/1999 or 13:61:00. If parsing is lenient, values will "rollover" into the units of the next lower unit of precision. Thus 4/31/1999 will parse as 5/1/1999 and 13:61:00 as 14:01:00.
        Parameters:
        lenient - indicates whether parsing should be lenient.
      • isLenient

        public boolean isLenient()
        Indicates whether parsing is to be lenient with respect to well-formed but invalid values.
        Returns:
        whether parsing should be lenient
      • setPivotYear

        public void setPivotYear​(int year)
        Specifies the midpoint of the 100-year period for two-digit dates. When parsing, years will be assumed to be within the range year-50 and year+49.
        Parameters:
        year - the midpoint of the range for parsed year values
      • getPivotYear

        public int getPivotYear()
        Gets the year defining the midpoint of the 100-year period assumed for two-digit year values.
        Returns:
        the midpoint of the valid period