Java Parse Date parseDateHeader(String value)

Here you can find the source of parseDateHeader(String value)

Description

parse Date Header

License

Apache License

Declaration

public static Long parseDateHeader(String value) 

Method Source Code

//package com.java2s;
/*/*from ww w .j  a v  a2  s .co m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 {
    private static final String[] HTTP_REQUEST_DATE_HEADER = { "EEE, dd MMM yyyy HH:mm:ss zzz",
            "EEEEEE, dd-MMM-yy HH:mm:ss zzz", "EEE MMMM d HH:mm:ss yyyy" };
    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");

    public static Long parseDateHeader(String value) {
        Date date = null;
        for (int i = 0; (date == null) && (i < HTTP_REQUEST_DATE_HEADER.length); i++) {
            try {
                SimpleDateFormat format = new SimpleDateFormat(HTTP_REQUEST_DATE_HEADER[i], Locale.US);
                format.setTimeZone(GMT);
                date = format.parse(value);
            } catch (ParseException e) {
                // all fine
            }
        }
        if (date == null) {
            return null;
        }
        return Long.valueOf(date.getTime());
    }
}

Related

  1. parseDateFromDateTimeStr(String date)
  2. parseDateFromDefault(String dateString)
  3. parseDateFromHeader(String datestr)
  4. parseDateFromString(String valor, String formatoFecha)
  5. parseDateHeader(String header)
  6. parseDateHHmm(java.util.Date date)
  7. parseDateHHMM(String hhmm)
  8. parseDateHMSMZ(String dateString)
  9. parseDateList(List dateList)