Java Parse HTTP Date parseHttpDate(String value)

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

Description

parse Http Date

License

Apache License

Declaration

public static Date parseHttpDate(String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static Date parseHttpDate(String value) {
        try {/*w w  w. j ava2s. co m*/
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
            Date expires = simpleDateFormat.parse(value);
            return expires;
        } catch (Exception e) {
            return tryParseDate(value);
        }
    }

    @SuppressWarnings("deprecation")
    public static Date tryParseDate(String value) {
        try {
            return new Date(Date.parse(value));
        } catch (Exception e) {
            return new Date();
        }
    }

    @SuppressWarnings("deprecation")
    public static Date tryParseDate(String value, Date defaultValue) {
        try {
            return new Date(Date.parse(value));
        } catch (Exception e) {
            return defaultValue;
        }
    }
}

Related

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