- java.lang.Object
-
- java.lang.Enum<DateFormats>
-
- org.refcodes.time.DateFormats
-
- All Implemented Interfaces:
Serializable,Comparable<DateFormats>
public enum DateFormats extends Enum<DateFormats>
TheDateFormatsrepresent sets ofDateFormatdefinitions. Such a set is most useful to parse back aStringinto aDatewhen there are multiple possibleStringrepresentations. E.g. a cookie's date representation might be either as defined by theDateFormat.NETSCAPE_COOKIE_DATE_FORMATor by theDateFormat.ALTERNATE_COOKIE_DATE_FORMAT.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description COOKIE_DATE_FORMATSSet ofDateFormatdefinitions commonly used by cookies.DEFAULT_DATE_FORMATSSound set of commonDateFormatdefinitions with no special addressee.DEFAULT_DATE_FORMATS_SHORTSound set of common shortDateFormatdefinitions with no special addressee.INTERNET_DATE_FORMATSSet ofDateFormatdefinitions found in heterogeneous internet related services.ISO_DATE_FORMATSSet of commonDateFormatISO definitions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DateasDate(String aDateString)Tries to create aDateby harnessing theDateTimeFormatterinstances known by this enumeration.static LocalDateasLocalDate(String aDateString)Tries to create aLocalDateby harnessing theDateTimeFormatterinstances known by this enumeration.static LocalDateTimeasLocalDateTime(String aDateString)Tries to create aLocalDateTimeby harnessing theDateTimeFormatterinstances known by this enumeration.DateTimeFormatter[]getDateFormats()Gets the date formats.DatetoDate(String aDateString)Creates aDatefrom the providedStringusing the date formats as retrieved by thegetDateFormats()method.LocalDatetoLocalDate(String aDateString)Creates aLocalDatefrom the providedStringusing the date formats as retrieved by thegetDateFormats()method.LocalDateTimetoLocalDateTime(String aDateString)Creates aLocalDateTimefrom the providedStringusing the date formats as retrieved by thegetDateFormats()method.static DateFormatsvalueOf(String name)Returns the enum constant of this type with the specified name.static DateFormats[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
DEFAULT_DATE_FORMATS
public static final DateFormats DEFAULT_DATE_FORMATS
Sound set of commonDateFormatdefinitions with no special addressee.
-
DEFAULT_DATE_FORMATS_SHORT
public static final DateFormats DEFAULT_DATE_FORMATS_SHORT
Sound set of common shortDateFormatdefinitions with no special addressee.
-
COOKIE_DATE_FORMATS
public static final DateFormats COOKIE_DATE_FORMATS
Set ofDateFormatdefinitions commonly used by cookies.
-
INTERNET_DATE_FORMATS
public static final DateFormats INTERNET_DATE_FORMATS
Set ofDateFormatdefinitions found in heterogeneous internet related services.
-
ISO_DATE_FORMATS
public static final DateFormats ISO_DATE_FORMATS
Set of commonDateFormatISO definitions.
-
-
Method Detail
-
values
public static DateFormats[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DateFormats c : DateFormats.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DateFormats valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException- if the argument is null
-
getDateFormats
public DateTimeFormatter[] getDateFormats()
Gets the date formats.- Returns:
- the date formats
-
toDate
public Date toDate(String aDateString) throws DateTimeException
Creates aDatefrom the providedStringusing the date formats as retrieved by thegetDateFormats()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 aDateinstance.- Returns:
- The
Dateinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
toLocalDate
public LocalDate toLocalDate(String aDateString) throws DateTimeException
Creates aLocalDatefrom the providedStringusing the date formats as retrieved by thegetDateFormats()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 aDateinstance.- Returns:
- The
Dateinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
toLocalDateTime
public LocalDateTime toLocalDateTime(String aDateString) throws DateTimeException
Creates aLocalDateTimefrom the providedStringusing the date formats as retrieved by thegetDateFormats()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 aDateinstance.- Returns:
- The
Dateinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
asDate
public static Date asDate(String aDateString) throws DateTimeException
Tries to create aDateby harnessing theDateTimeFormatterinstances known by this enumeration.- Parameters:
aDateString- The date text to be converted to aDateinstance.- Returns:
- The
Dateinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
asLocalDate
public static LocalDate asLocalDate(String aDateString) throws DateTimeException
Tries to create aLocalDateby harnessing theDateTimeFormatterinstances known by this enumeration.- Parameters:
aDateString- The date text to be converted to aLocalDateinstance.- Returns:
- The
LocalDateinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
asLocalDateTime
public static LocalDateTime asLocalDateTime(String aDateString) throws DateTimeException
Tries to create aLocalDateTimeby harnessing theDateTimeFormatterinstances known by this enumeration.- Parameters:
aDateString- The date text to be converted to aLocalDateinstance.- Returns:
- The
LocalDateTimeinstance as of the date text. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
-