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 SummaryFieldsModifier and TypeFieldDescriptionstatic final StringDate format pattern used to parse HTTP date headers in ANSI Casctime() format.static final StringDate format pattern used to parse HTTP date headers in RFC 1036 format.static final StringDate format pattern used to parse HTTP date headers in RFC 1123 format.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidClears thread-local variable containingDateFormatcache.static StringformatDate(Date date, String pattern) Formats the given date according to the specified pattern.static DateTimeFormattergetFormatter(String pattern) Returns aDateTimeFormatterusing either a pattern or predefined pattern name.static CalendarParses an ISO8601 string and converts it to aCalendar.static StringPads out an ISO8601 string so that it can be parsed usingDatatypeConverter.parseDateTime(String).
- 
Field Details- 
PATTERN_RFC1123Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
 
- 
PATTERN_RFC1036Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
 
- 
PATTERN_ASCTIMEDate format pattern used to parse HTTP date headers in ANSI Casctime() format.- See Also:
 
 
- 
- 
Constructor Details- 
DateUtilspublic DateUtils()
 
- 
- 
Method Details- 
parseISO8601CalendarParses 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.
 
- 
formatDateFormats the given date according to the specified pattern.The pattern must conform to that used by the simple date formatclass.- 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:
 
- 
clearThreadLocalClears thread-local variable containingDateFormatcache.
- 
toValidISO8601DTPads 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.
 
- 
getFormatterReturns aDateTimeFormatterusing 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.
 
 
-