• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
DateUtils Class Reference

A utility class for parsing and formatting HTTP dates as used in cookies and other headers. More...

Description

This class handles dates as defined by RFC 2616 section 3.3.1 as well as some other common non-standard formats.

Author
Christopher Brown
Michael Becke

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Static Public Member Functions

static Date parseDate (String dateValue) throws DateParseException
 Parses a date value. More...
 
static Date parseDate (final String dateValue, String[] dateFormats) throws DateParseException
 Parses the date value using the given date formats. More...
 
static Date parseDate (String dateValue, String[] dateFormats, Date startDate) throws DateParseException
 Parses the date value using the given date formats. More...
 
static String formatDate (Date date)
 Formats the given date according to the RFC 1123 pattern. More...
 
static String formatDate (Date date, String pattern)
 Formats the given date according to the specified pattern. More...
 

Static Public Attributes

static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz"
 Date format pattern used to parse HTTP date headers in RFC 1123 format.
 
static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz"
 Date format pattern used to parse HTTP date headers in RFC 1036 format.
 
static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy"
 Date format pattern used to parse HTTP date headers in ANSI C asctime() format.
 

Member Function Documentation

◆ parseDate() [1/3]

static Date parseDate ( String  dateValue) throws DateParseException
static

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

Parameters
dateValuethe date value to parse
Returns
the parsed date
Exceptions
DateParseExceptionif the value could not be parsed using any of the supported date formats

◆ parseDate() [2/3]

static Date parseDate ( final String  dateValue,
String[]  dateFormats 
) throws DateParseException
static
Parameters
dateValuethe date value to parse
dateFormatsthe date formats to use
Returns
the parsed date
Exceptions
DateParseExceptionif none of the dataFormats could parse the dateValue

◆ parseDate() [3/3]

static Date parseDate ( String  dateValue,
String[]  dateFormats,
Date  startDate 
) throws DateParseException
static
Parameters
dateValuethe date value to parse
dateFormatsthe date formats to use
startDateDuring 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
the parsed date
Exceptions
DateParseExceptionif none of the dataFormats could parse the dateValue

◆ formatDate() [1/2]

static String formatDate ( Date  date)
static
Parameters
dateThe date to format.
Returns
An RFC 1123 formatted date string.
See also
PATTERN_RFC1123

◆ formatDate() [2/2]

static String formatDate ( Date  date,
String  pattern 
)
static

The pattern must conform to that used by the SimpleDateFormat simple date format} class.

Parameters
dateThe date to format.
patternThe pattern to use for formatting the date.
Returns
A formatted date string.
Exceptions
IllegalArgumentExceptionIf the given date pattern is invalid.