public static Date parseDate ( final String date ) { /* IE9 sends a superflous lenght parameter after date in the If-Modified-Since header, which needs to be stripped before parsing. */ final int semicolonIndex = date . indexOf ( ' ' ) ; final String trimmedDate = semicolonIndex >= 0 ? date . substring ( 0 , semicolonIndex ) : date ; ParsePosition pp = new ParsePosition ( 0 ) ; SimpleDateFormat dateFormat = RFC1123_PATTERN_FORMAT . get ( ) ; dateFormat . setTimeZone ( GMT_ZONE ) ; Date val = dateFormat . parse ( trimmedDate , pp ) ; if ( val != null && pp . getIndex ( ) == trimmedDate . length ( ) ) { return val ; } pp = new ParsePosition ( 0 ) ; dateFormat = new SimpleDateFormat ( RFC1036_PATTERN , LOCALE_US ) ; dateFormat . setTimeZone ( GMT_ZONE ) ; val = dateFormat . parse ( trimmedDate , pp ) ; if ( val != null && pp . getIndex ( ) == trimmedDate . length ( ) ) { return val ; } pp = new ParsePosition ( 0 ) ; dateFormat = new SimpleDateFormat ( ASCITIME_PATTERN , LOCALE_US ) ; dateFormat . setTimeZone ( GMT_ZONE ) ; val = dateFormat . parse ( trimmedDate , pp ) ; if ( val != null && pp . getIndex ( ) == trimmedDate . length ( ) ) { return val ; } pp = new ParsePosition ( 0 ) ; dateFormat = new SimpleDateFormat ( OLD_COOKIE_PATTERN , LOCALE_US ) ; dateFormat . setTimeZone ( GMT_ZONE ) ; val = dateFormat . parse ( trimmedDate , pp ) ; if ( val != null && pp . getIndex ( ) == trimmedDate . length ( ) ) { return val ; } return null ; }
Attempts to pass a HTTP date .