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>
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.
-
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.DatetoDate(java.lang.String aDateString)Creates a date from the providedStringusing the date formats as retrieved by thegetDateFormats()method.static DateFormatsvalueOf(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 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.
-
-
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.DateTimeExceptionCreates a date from 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:
java.time.DateTimeException- the date time exception
-
-