Java Parse HTTP Date parseHttpDateFormat(String httpDateFormat)

Here you can find the source of parseHttpDateFormat(String httpDateFormat)

Description

Can be used to parse http times.

License

Apache License

Parameter

Parameter Description
httpDateFormat in http format: Date: Tue, 26 Mar 2013 13:47:13 GMT

Exception

Parameter Description
ParseException If something goes wrong.

Return

A nice "Date" object containing that http timestamp.

Declaration

public static Date parseHttpDateFormat(String httpDateFormat) throws ParseException 

Method Source Code


//package com.java2s;
/*/*ww  w . j  av  a 2 s.  c  o  m*/
 * Copyright (C) 2014 the original author or authors.
 *
 * 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.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    /**
     * Can be used to parse http times. For instance something like a http
     * header Date: Tue, 26 Mar 2013 13:47:13 GMT
     * <p/>
     * INFO: consider the JodaTime based
     * DateUtil.parseHttpDateFormatToDateTime(...) version
     *
     * @param httpDateFormat in http format: Date: Tue, 26 Mar 2013 13:47:13 GMT
     * @return A nice "Date" object containing that http timestamp.
     * @throws ParseException If something goes wrong.
     */
    public static Date parseHttpDateFormat(String httpDateFormat) throws ParseException {
        return parseHttpDateFormatToDateTime(httpDateFormat);
    }

    /**
     * Can be used to parse http times. For instance something like a http
     * header Date: Tue, 26 Mar 2013 13:47:13 GMT
     *
     * @param httpDateFormat in http format: Date: Tue, 26 Mar 2013 13:47:13 GMT
     * @return A nice "DateTime" (JodaTime) object containing that http
     * timestamp.
     * @throws ParseException If something goes wrong.
     */
    public static Date parseHttpDateFormatToDateTime(String httpDateFormat) throws ParseException {
        return getRFC1123_DateFormat().parse(httpDateFormat);
    }

    /**
     * From here: http://www.ietf.org/rfc/rfc1123.txt
     */
    static DateFormat getRFC1123_DateFormat() {
        return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    }
}

Related

  1. parseHttpDate(String ifModifiedSince)
  2. parseHttpDate(String s)
  3. parseHttpDate(String string)
  4. parseHttpDate(String stringValue)
  5. parseHttpDate(String value)
  6. parseHttpDateString(String s)