Package org.refcodes.time
Enum DateFormats
- java.lang.Object
-
- java.lang.Enum<DateFormats>
-
- org.refcodes.time.DateFormats
-
public enum DateFormats extends java.lang.Enum<DateFormats>
TheDateFormats
represent sets ofDateFormat
definitions. Such a set is most useful to parse back aString
into aDate
when there are multiple possibleString
representations. E.g. a cookie's date representation might be either as defined by theDateFormat.NETSCAPE_COOKIE_DATE_FORMAT
or by theDateFormat.ALTERNATE_COOKIE_DATE_FORMAT
.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description COOKIE_DATE_FORMATS
Set ofDateFormat
definitions commonly used by cookies.DEFAULT_DATE_FORMATS
Sound set of commonDateFormat
definitions with no special addressee.DEFAULT_DATE_FORMATS_SHORT
Sound set of common shortDateFormat
definitions with no special addressee.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.format.DateTimeFormatter[]
getDateFormats()
Gets the date formats.java.util.Date
toDate(java.lang.String aDateString)
Creates a date from the providedString
using the date formats as retrieved by thegetDateFormats()
method.static DateFormats
valueOf(java.lang.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 commonDateFormat
definitions with no special addressee.
-
DEFAULT_DATE_FORMATS_SHORT
public static final DateFormats DEFAULT_DATE_FORMATS_SHORT
Sound set of common shortDateFormat
definitions with no special addressee.
-
COOKIE_DATE_FORMATS
public static final DateFormats COOKIE_DATE_FORMATS
Set ofDateFormat
definitions commonly used by cookies.
-
-
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(java.lang.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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getDateFormats
public java.time.format.DateTimeFormatter[] getDateFormats()
Gets the date formats.- Returns:
- the date formats
-
toDate
public java.util.Date toDate(java.lang.String aDateString) throws java.time.DateTimeException
Creates a date from the providedString
using 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 aDate
instance.- Returns:
- The
Date
instance as of the date text. - Throws:
java.time.DateTimeException
- the date time exception
-
-