Java Parse Date parseDateRfc822(String str)

Here you can find the source of parseDateRfc822(String str)

Description

Parse a string in RFC822 GMT format.

License

Apache License

Parameter

Parameter Description
str string to parse.

Return

parsed date, null if the string was null or in an invalid format.

Declaration

static Date parseDateRfc822(String str) 

Method Source Code

//package com.java2s;
/**/*from w  ww . j  a  v  a 2 s.  c  o 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 {
    /**
     * Parse a string in RFC822 GMT format.
     *
     * @param str string to parse.
     * @return parsed date, <code>null</code> if the string was <code>null</null> or in an invalid format.
     */
    static Date parseDateRfc822(String str) {
        if (str != null) {
            try {
                SimpleDateFormat dateFormater = new SimpleDateFormat(
                        "EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
                dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
                return dateFormater.parse(str);
            } catch (ParseException ex) {
                return null;
            }
        }
        return null;
    }
}

Related

  1. parseDateLoose(String dateString)
  2. parseDateNewFormat(String sDate)
  3. parseDateNoTimeWithDelimit(String sDate, String delimit)
  4. parseDateOrTimeString(String aDateString, String aFormatString)
  5. parseDateRFC(String value)
  6. parseDates(String query)
  7. parseDateStrFormat(String strDate)
  8. parseDateString(String dateStr)
  9. parseDateString(String dateString)