net.rim.device.api.io.http
Class HttpDateParser
java.lang.Object
net.rim.device.api.io.http.HttpDateParser
public final class HttpDateParser
- extends Object
A little utility class designed to parse dates in one of the three formats
supported by HTTP 1.1. The formats are:
- Sun, 06 Nov 1994 08:49:37 GMT (RFC 822, updated by RFC 1123)
- Sunday, 06-Nov-94 08:49:37 GMT (RFC 850, obsoleted by RFC 1036)
- Sun Nov 6 08:49:37 1994 (ANSI C's asctime() format)
Note that the first format is preferred, and in fact HTTP 1.1 clients and servers
MUST only generate dates in that format. However, for backwards compatibility,
they MUST accept all three formats.
Sample code
// Assuming getHeaderField() of HttpConnection interface is implemented.
String value = getHeaderField( HttpProtocolConstants.HEADER_DATE );
if (value != null)
{
long parsed = HttpDateParser.parse( value );
}
- Category:
- Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
- Since:
- BlackBerry API 4.0.0
Method Summary |
|
static long |
parse(String date)
Parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 GMT. |
parse
public static long parse(String date)
- Parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.
The date is assumed to be of the format:
- "Wdy, DD Mon YY"
- "Wdy, DD Mon YYYY"
- "Wdy, DD Mon YY HH:MM:SS"
- "Wdy, DD Mon YY HH:MM:SS GMT"
- "Wdy, DD Mon YY HH:MM:SS TZD"
- "Wdy, DD Mon YY HHMMSS"
- "Wdy, DD Mon YY HHMMSS GMT"
- "Wdy, DD Mon YY HHMMSS TZD"
- "Wdy, DD Mon YYYY HH:MM:SS"
- "Wdy, DD Mon YYYY HH:MM:SS GMT"
- "Wdy, DD Mon YYYY HH:MM:SS TZD"
- "Wdy, DD Mon YYYY HHMMSS"
- "Wdy, DD Mon YYYY HHMMSS GMT"
- "Wdy, DD Mon YYYY HHMMSS TZD"
- "Wdy, Mon DD YY HH:MM:SS"
- "Wdy, Mon DD YY HH:MM:SS GMT"
- "Wdy, Mon DD YY HH:MM:SS TZD"
- "Wdy, Mon DD YY HHMMSS"
- "Wdy, Mon DD YY HHMMSS GMT"
- "Wdy, Mon DD YY HHMMSS TZD"
- "Wdy, Mon DD YYYY HH:MM:SS"
- "Wdy, Mon DD YYYY HH:MM:SS GMT"
- "Wdy, Mon DD YYYY HH:MM:SS TZD"
- "Wdy, Mon DD YYYY HHMMSS"
- "Wdy, Mon DD YYYY HHMMSS GMT"
- "Wdy, Mon DD YYYY HHMMSS TZD"
- "Wdy, DD Mon YY, HH:MM:SS"
- "Wdy, DD Mon YY, HH:MM:SS GMT"
- "Wdy, DD Mon YY, HH:MM:SS TZD"
- "Wdy, DD Mon YY, HHMMSS"
- "Wdy, DD Mon YY, HHMMSS GMT"
- "Wdy, DD Mon YY, HHMMSS TZD"
- "Wdy, DD Mon YYYY, HH:MM:SS"
- "Wdy, DD Mon YYYY, HH:MM:SS GMT"
- "Wdy, DD Mon YYYY, HH:MM:SS TZD"
- "Wdy, DD-Mon-YY HH:MM:SS"
- "Wdy, DD-Mon-YY HH:MM:SS GMT"
- "Wdy, DD-Mon-YY HH:MM:SS TZD"
- "Wdy, DD-Mon-YY HHMMSS"
- "Wdy, DD-Mon-YY HHMMSS GMT"
- "Wdy, DD-Mon-YY HHMMSS TZD"
- "Wdy, DD-Mon-YY, HH:MM:SS"
- "Wdy, DD-Mon-YY, HH:MM:SS GMT"
- "Wdy, DD-Mon-YY, HH:MM:SS TZD"
- "Wdy, DD-Mon-YY, HHMMSS"
- "Wdy, DD-Mon-YY, HHMMSS GMT"
- "Wdy, DD-Mon-YY, HHMMSS TZD"
- "Wdy, DD-Mon-YYYY HH:MM:SS"
- "Wdy, DD-Mon-YYYY HH:MM:SS GMT"
- "Wdy, DD-Mon-YYYY HH:MM:SS TZD"
- "Wdy, DD-Mon-YYYY HHMMSS"
- "Wdy, DD-Mon-YYYY HHMMSS GMT"
- "Wdy, DD-Mon-YYYY HHMMSS TZD"
- "Wdy, DD-Mon-YYYY, HH:MM:SS"
- "Wdy, DD-Mon-YYYY, HH:MM:SS GMT"
- "Wdy, DD-Mon-YYYY, HH:MM:SS TZD"
- "Wdy, DD-Mon-YYYY, HHMMSS"
- "Wdy, DD-Mon-YYYY, HHMMSS GMT"
- "Wdy, DD-Mon-YYYY, HHMMSS TZD"
- "Weekday, DD-Mon-YY HH:MM:SS"
- "Weekday, DD-Mon-YY HH:MM:SS GMT"
- "Weekday, DD-Mon-YY HH:MM:SS TZD"
- "Weekday, DD-Mon-YY HHMMSS"
- "Weekday, DD-Mon-YY HHMMSS GMT"
- "Weekday, DD-Mon-YY HHMMSS GMT"
- "Weekday, DD-Mon-YYYY HH:MM:SS"
- "Weekday, DD-Mon-YYYY HH:MM:SS GMT"
- "Weekday, DD-Mon-YYYY HH:MM:SS TZD"
- "Weekday, DD-Mon-YYYY HHMMSS"
- "Weekday, DD-Mon-YYYY HHMMSS GMT"
- "Weekday, DD-Mon-YYYY HHMMSS TZD"
- "Wdy Mon DD HH:MM:SS YYYY"
- "YYYY" (eg 1997)
- "YYYY-MM" (eg 1997-07)
- "YYYY-MM-DD" (eg 1997-07-16)
- "YYYY-MM-DDThh:mmTZD" (eg 1997-07-16T19:20+01:00)
- "YYYY-MM-DDThh:mm:ssTZD" (eg 1997-07-16T19:20:30+01:00)
- "YYYY-MM-DDThh:mm:ss.sTZD" (eg 1997-07-16T19:20:30.45+01:00)
When parsing a date string using the abbreviated year pattern ("YY") it must interpret the
abbreviated year relative to some century. It does this using the
algorithm described in http://tools.ietf.org/id/draft-ietf-httpstate-cookie-09.txt,
section 5.5.1:
3. If the year-value is greater than 68 and less than 100, increment
the year-value by 1900.
4. If the year-value is greater than or equal to 0 and less than 69,
increment the year-value by 2000.
- Parameters:
date
- The string to parse.
- Returns:
- The number of milliseconds.
- Category:
- Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
- Since:
- BlackBerry API 4.0.0
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.