- java.lang.Object
-
- java.lang.Enum<DateFormats>
-
- org.refcodes.time.DateFormats
-
- All Implemented Interfaces:
Serializable
,Comparable<DateFormats>
public enum DateFormats extends 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.INTERNET_DATE_FORMATS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Date
asDate(String aDateString)
Tries to create a Date by harnessing theDateTimeFormatter
instances known by this enumeration.DateTimeFormatter[]
getDateFormats()
Gets the date formats.Date
toDate(String aDateString)
Creates a date from the providedString
using the date formats as retrieved by thegetDateFormats()
method.static DateFormats
valueOf(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.
-
INTERNET_DATE_FORMATS
public static final DateFormats INTERNET_DATE_FORMATS
-
-
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 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:
DateTimeException
- Thrown in case none of the providedDateTimeFormatter
instances was able to parse the string. Then the first caughtDateTimeException
is thrown.
-
asDate
public static Date asDate(String aDateString) throws DateTimeException
Tries to create a Date by harnessing theDateTimeFormatter
instances known by this enumeration.- Parameters:
aDateString
- The date text to be converted to aDate
instance.- Returns:
- The
Date
instance as of the date text. - Throws:
DateTimeException
- Thrown in case none of the providedDateTimeFormatter
instances was able to parse the string. Then the first caughtDateTimeException
is thrown.
-
-