Java Parse Date Pattern YYYY parseExpireField(String timestring)

Here you can find the source of parseExpireField(String timestring)

Description

parse Expire Field

License

Open Source License

Declaration

public static Date parseExpireField(String timestring) 

Method Source Code


//package com.java2s;
/*/*ww w .  j  a  v a2s  .c om*/
 * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    public final static ThreadLocal<SimpleDateFormat[]> SIMPLE_DATE_FORMATS = new ThreadLocal<SimpleDateFormat[]>() {
        protected SimpleDateFormat[] initialValue() {

            return new SimpleDateFormat[] { new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), // RFC1123
                    new SimpleDateFormat("EEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), // RFC1036
                    new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US), // ASCTIME
                    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US),
                    new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US),
                    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US),
                    new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss Z", Locale.US) };
        }
    };

    public static Date parseExpireField(String timestring) {
        SimpleDateFormat[] sdfs = SIMPLE_DATE_FORMATS.get();
        for (SimpleDateFormat sdf : sdfs) {
            Date date = sdf.parse(timestring, new ParsePosition(0));
            if (date != null)
                return date;
        }
        return null;
    }
}

Related

  1. parseDT(String fmt, String timeline)
  2. parseDueDate(String date)
  3. parseEapoDate(String date)
  4. parseEuropeanDateAnd12HrsTimeString(String aDateString, String aTimeString)
  5. parseEXIFFormat(String dateString)
  6. parseFormattedTime(String formattedTime)
  7. parseFTPDate(String dateStr)
  8. parseFullDate(String paramName, String dateStr)
  9. parseFullTime(String str)