Package org.apache.juneau.internal
Class DateUtils
java.lang.Object
org.apache.juneau.internal.DateUtils
A utility class for parsing and formatting HTTP dates as used in cookies and other headers.
This class handles dates as defined by RFC 2616 section 3.3.1 as well as some other common non-standard formats.
This class was copied from HttpClient 4.3.
See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Date format pattern used to parse HTTP date headers in ANSI Casctime() format.static final String
Date format pattern used to parse HTTP date headers in RFC 1036 format.static final String
Date format pattern used to parse HTTP date headers in RFC 1123 format. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears thread-local variable containingDateFormat
cache.static String
formatDate
(Date date, String pattern) Formats the given date according to the specified pattern.static DateTimeFormatter
getFormatter
(String pattern) Returns aDateTimeFormatter
using either a pattern or predefined pattern name.static Calendar
Parses an ISO8601 string and converts it to aCalendar
.static String
Pads out an ISO8601 string so that it can be parsed usingDatatypeConverter.parseDateTime(String)
.
-
Field Details
-
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
-
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
-
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime() format.- See Also:
-
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
parseISO8601Calendar
Parses an ISO8601 string and converts it to aCalendar
.- Parameters:
s
- The string to parse.- Returns:
- The parsed value, or
null if the string wasnull or empty.
-
formatDate
Formats the given date according to the specified pattern.The pattern must conform to that used by the
simple date format
class.- Parameters:
date
- The date to format.pattern
- The pattern to use for formatting the date.- Returns:
- A formatted date string.
- Throws:
IllegalArgumentException
- If the given date pattern is invalid.- See Also:
-
clearThreadLocal
Clears thread-local variable containingDateFormat
cache. -
toValidISO8601DT
Pads out an ISO8601 string so that it can be parsed usingDatatypeConverter.parseDateTime(String)
."2001-07-04T15:30:45-05:00" ->"2001-07-04T15:30:45-05:00" "2001-07-04T15:30:45Z" ->"2001-07-04T15:30:45Z" "2001-07-04T15:30:45.1Z" ->"2001-07-04T15:30:45.1Z" "2001-07-04T15:30Z" ->"2001-07-04T15:30:00Z" "2001-07-04T15:30" ->"2001-07-04T15:30:00" "2001-07-04" ->"2001-07-04T00:00:00" "2001-07" ->"2001-07-01T00:00:00" "2001" ->"2001-01-01T00:00:00"
- Parameters:
in
- The string to pad.- Returns:
- The padded string.
-
getFormatter
Returns aDateTimeFormatter
using either a pattern or predefined pattern name.- Parameters:
pattern
- The pattern (e.g."yyyy-MM-dd" ) or pattern name (e.g."ISO_INSTANT" ).- Returns:
- The formatter.
-