Top Description Fields Constructors Methods
org.apache.http.impl.cookie

public final Class DateUtils

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
java.util.Date, .TimeZone

Deprecated

(4.3) Use org.apache.http.client.utils.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.
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final TimeZone
public static final String
PATTERN_ASCTIME

Date format pattern used to parse HTTP date headers in ANSI C asctime() format.

public static final String
PATTERN_RFC1036

Date format pattern used to parse HTTP date headers in RFC 1036 format.

public static final String
PATTERN_RFC1123

Date format pattern used to parse HTTP date headers in RFC 1123 format.

Constructor Summary

AccessConstructor and Description
private
DateUtils()

This class should not be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

An RFC 1123 formatted date string.
formatDate
(final Date
The date to format.
date
)

Formats the given date according to the RFC 1123 pattern.

public static String

Returns:

A formatted date string.
formatDate
(final Date
The date to format.
date
,
final String
The pattern to use for formatting the date.
pattern
)

Formats the given date according to the specified pattern.

public static Date

Returns:

the parsed date
parseDate
(final String
the date value to parse
dateValue
)

Parses a date value.

public static Date

Returns:

the parsed date
parseDate
(final String
the date value to parse
dateValue
,
final String[]
the date formats to use
dateFormats
)

Parses the date value using the given date formats.

public static Date

Returns:

the parsed date
parseDate
(final String
the date value to parse
dateValue
,
final String[]
the date formats to use
dateFormats
,
final Date
During parsing, two digit years will be placed in the range startDate to startDate + 100 years. This value may be null. When null is given as a parameter, year 2000 will be used.
startDate
)

Parses the date value using the given date formats.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GMTback to summary
public static final TimeZone GMT
PATTERN_ASCTIMEback to summary
public static final String PATTERN_ASCTIME

Date format pattern used to parse HTTP date headers in ANSI C asctime() format.

PATTERN_RFC1036back to summary
public static final String PATTERN_RFC1036

Date format pattern used to parse HTTP date headers in RFC 1036 format.

PATTERN_RFC1123back to summary
public static final String PATTERN_RFC1123

Date format pattern used to parse HTTP date headers in RFC 1123 format.

Constructor Detail

DateUtilsback to summary
private DateUtils()

This class should not be instantiated.

Method Detail

formatDateback to summary
public static String formatDate(final Date date)

Formats the given date according to the RFC 1123 pattern.

Parameters
date:Date

The date to format.

Returns:String

An RFC 1123 formatted date string.

See Also
PATTERN_RFC1123
formatDateback to summary
public static String formatDate(final Date date, final String pattern)

Formats the given date according to the specified pattern. The pattern must conform to that used by the simple date format class.

Parameters
date:Date

The date to format.

pattern:String

The pattern to use for formatting the date.

Returns:String

A formatted date string.

Exceptions
IllegalArgumentException:
If the given date pattern is invalid.
See Also
java.text.SimpleDateFormat
parseDateback to summary
public static Date parseDate(final String dateValue) throws DateParseException

Parses a date value. The formats used for parsing the date value are retrieved from the default http params.

Parameters
dateValue:String

the date value to parse

Returns:Date

the parsed date

Exceptions
DateParseException:
if the value could not be parsed using any of the supported date formats
parseDateback to summary
public static Date parseDate(final String dateValue, final String[] dateFormats) throws DateParseException

Parses the date value using the given date formats.

Parameters
dateValue:String

the date value to parse

dateFormats:String[]

the date formats to use

Returns:Date

the parsed date

Exceptions
DateParseException:
if none of the dataFormats could parse the dateValue
parseDateback to summary
public static Date parseDate(final String dateValue, final String[] dateFormats, final Date startDate) throws DateParseException

Parses the date value using the given date formats.

Parameters
dateValue:String

the date value to parse

dateFormats:String[]

the date formats to use

startDate:Date

During parsing, two digit years will be placed in the range startDate to startDate + 100 years. This value may be null. When null is given as a parameter, year 2000 will be used.

Returns:Date

the parsed date

Exceptions
DateParseException:
if none of the dataFormats could parse the dateValue