Here you can find the source of parseHttpDate(String string)
Parse a String into a Date according to the HTTP/1.1 RFC (Mon, 31 Jan 2000 11:59:00 GMT
).
Parameter | Description |
---|---|
string | the String to parse. |
public static Date parseHttpDate(String string)
//package com.java2s; /* ========================================================================== * * Copyright (C) 2004-2006, Pier Fumagalli <http://could.it/> * * All rights reserved. * * ========================================================================== * * * * 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. * * * * ========================================================================== */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /** <p>The {@link SimpleDateFormat} RFC-822 date format.</p> */ private static final String FORMAT_822 = "EEE, dd MMM yyyy HH:mm:ss 'GMT'"; /** <p>The {@link TimeZone} to use for dates.</p> */ private static final TimeZone TIMEZONE = TimeZone.getTimeZone("GMT"); /** <p>The {@link Locale} to use for dates.</p> */ private static final Locale LOCALE = Locale.US; /**/*from ww w .j a va2 s . co m*/ * <p>Parse a {@link String} into a {@link Date} according to the * HTTP/1.1 RFC (<code>Mon, 31 Jan 2000 11:59:00 GMT</code>).</p> * * @param string the {@link String} to parse. * @return a {@link Date} instance or <b>null</b> if the date was null or * if there was an error parsing the specified {@link String}. */ public static Date parseHttpDate(String string) { if (string == null) return null; SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_822, LOCALE); formatter.setTimeZone(TIMEZONE); try { return formatter.parse(string); } catch (ParseException exception) { return null; } } }