Fields Summary |
---|
public static final String | PATTERN_RFC1123Date format pattern used to parse HTTP date headers in RFC 1123 format. |
public static final String | PATTERN_RFC1036Date format pattern used to parse HTTP date headers in RFC 1036 format. |
public static final String | PATTERN_ASCTIMEDate format pattern used to parse HTTP date headers in ANSI C
asctime() format. |
private static final String[] | DEFAULT_PATTERNS |
private static final Date | DEFAULT_TWO_DIGIT_YEAR_START |
public static final TimeZone | GMT |
Methods Summary |
---|
public static java.lang.String | formatDate(java.util.Date date)Formats the given date according to the RFC 1123 pattern.
return formatDate(date, PATTERN_RFC1123);
|
public static java.lang.String | formatDate(java.util.Date date, java.lang.String pattern)Formats the given date according to the specified pattern. The pattern
must conform to that used by the {@link SimpleDateFormat simple date
format} class.
if (date == null) throw new IllegalArgumentException("date is null");
if (pattern == null) throw new IllegalArgumentException("pattern is null");
SimpleDateFormat formatter = DateFormatHolder.formatFor(pattern);
return formatter.format(date);
|
public static java.util.Date | parseDate(java.lang.String dateValue)Parses a date value. The formats used for parsing the date value are retrieved from
the default http params.
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(GMT);
calendar.set(2000, Calendar.JANUARY, 1, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
return parseDate(dateValue, null, null);
|
public static java.util.Date | parseDate(java.lang.String dateValue, java.lang.String[] dateFormats)Parses the date value using the given date formats.
return parseDate(dateValue, dateFormats, null);
|
public static java.util.Date | parseDate(java.lang.String dateValue, java.lang.String[] dateFormats, java.util.Date startDate)Parses the date value using the given date formats.
if (dateValue == null) {
throw new IllegalArgumentException("dateValue is null");
}
if (dateFormats == null) {
dateFormats = DEFAULT_PATTERNS;
}
if (startDate == null) {
startDate = DEFAULT_TWO_DIGIT_YEAR_START;
}
// trim single quotes around date if present
// see issue #5279
if (dateValue.length() > 1
&& dateValue.startsWith("'")
&& dateValue.endsWith("'")
) {
dateValue = dateValue.substring (1, dateValue.length() - 1);
}
for (String dateFormat : dateFormats) {
SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
dateParser.set2DigitYearStart(startDate);
try {
return dateParser.parse(dateValue);
} catch (ParseException pe) {
// ignore this exception, we will try the next format
}
}
// we were unable to parse the date
throw new DateParseException("Unable to parse the date " + dateValue);
|