Enum Class DateFormats

java.lang.Object
java.lang.Enum<DateFormats>
org.refcodes.time.DateFormats
All Implemented Interfaces:
Serializable, Comparable<DateFormats>, Constable

public enum DateFormats extends Enum<DateFormats>
The DateFormats represent sets of DateFormat definitions. Such a set is most useful to parse back a String into a Date when there are multiple possible String representations. E.g. a cookie's date representation might be either as defined by the DateFormat.NETSCAPE_COOKIE_DATE_FORMAT or by the DateFormat.ALTERNATE_COOKIE_DATE_FORMAT.
  • Enum Constant Details

    • DEFAULT_DATE_FORMATS

      public static final DateFormats DEFAULT_DATE_FORMATS
      Sound set of common DateFormat definitions with no https://www.metacodes.pro addressee.
    • DEFAULT_DATE_FORMATS_SHORT

      public static final DateFormats DEFAULT_DATE_FORMATS_SHORT
      Sound set of common short DateFormat definitions with no https://www.metacodes.pro addressee.
    • INTERNET_DATE_FORMATS

      public static final DateFormats INTERNET_DATE_FORMATS
      Set of DateFormat definitions found in heterogeneous internet related services.
    • ISO_DATE_FORMATS

      public static final DateFormats ISO_DATE_FORMATS
      Set of common DateFormat ISO definitions.
  • Method Details

    • values

      public static DateFormats[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DateFormats valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getDateFormats

      public DateTimeFormatter[] getDateFormats()
      Gets the date formats.
      Returns:
      the date formats
    • toDate

      public Date toDate(String aDateString)
      Creates a Date from the provided String using the date formats as retrieved by the getDateFormats() method. If one date format fails, then the next one is used to parse the date text.
      Parameters:
      aDateString - The date text to be converted to a Date instance.
      Returns:
      The Date instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.
    • toLocalDate

      public LocalDate toLocalDate(String aDateString)
      Creates a LocalDate from the provided String using the date formats as retrieved by the getDateFormats() method. If one date format fails, then the next one is used to parse the date text.
      Parameters:
      aDateString - The date text to be converted to a Date instance.
      Returns:
      The Date instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.
    • toLocalDateTime

      public LocalDateTime toLocalDateTime(String aDateString)
      Creates a LocalDateTime from the provided String using the date formats as retrieved by the getDateFormats() method. If one date format fails, then the next one is used to parse the date text.
      Parameters:
      aDateString - The date text to be converted to a Date instance.
      Returns:
      The Date instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.
    • asDate

      public static Date asDate(String aDateString)
      Tries to create a Date by harnessing the DateTimeFormatter instances known by this enumeration.
      Parameters:
      aDateString - The date text to be converted to a Date instance.
      Returns:
      The Date instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.
    • asLocalDate

      public static LocalDate asLocalDate(String aDateString)
      Tries to create a LocalDate by harnessing the DateTimeFormatter instances known by this enumeration.
      Parameters:
      aDateString - The date text to be converted to a LocalDate instance.
      Returns:
      The LocalDate instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.
    • asLocalDateTime

      public static LocalDateTime asLocalDateTime(String aDateString)
      Tries to create a LocalDateTime by harnessing the DateTimeFormatter instances known by this enumeration.
      Parameters:
      aDateString - The date text to be converted to a LocalDate instance.
      Returns:
      The LocalDateTime instance as of the date text.
      Throws:
      DateTimeException - Thrown in case none of the provided DateTimeFormatter instances was able to parse the string. Then the first caught DateTimeException is thrown.