Java Parse HTTP Date parseHttpDate(String s)

Here you can find the source of parseHttpDate(String s)

Description

parse Http Date

License

Open Source License

Declaration

public static long parseHttpDate(String s) throws ParseException 

Method Source Code

//package com.java2s;
/**/*  w ww  .j a v  a  2 s .  c om*/
 * Copyright (c) 2013-2017, Kenneth Leung. All rights reserved.
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file epl-v10.html at the root of this distribution.
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 * You must not remove this notice, or any other, from this software.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    private static ThreadLocal<SimpleDateFormat> _fmt = new ThreadLocal<SimpleDateFormat>() {

        public SimpleDateFormat initialValue() {
            SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
            f.setTimeZone(TimeZone.getTimeZone("GMT"));
            return f;
        }

    };

    /**
     */
    public static long parseHttpDate(String s, long defaultValue) {
        try {
            return parseHttpDate(s);
        } catch (ParseException e) {
        }
        return defaultValue;
    }

    /**
     */
    public static long parseHttpDate(String s) throws ParseException {
        return getSDF().parse(s).getTime();
    }

    public static SimpleDateFormat getSDF() {
        return _fmt.get();
    }
}

Related

  1. parseHttpDate(String _dateStr)
  2. parseHttpDate(String dstr)
  3. parseHttpDate(String ifModifiedSince)
  4. parseHttpDate(String string)
  5. parseHttpDate(String stringValue)
  6. parseHttpDate(String value)
  7. parseHttpDateFormat(String httpDateFormat)