Android Date String Parse parseRFC822Date(String date)

Here you can find the source of parseRFC822Date(String date)

Description

parse RFC Date

License

Open Source License

Declaration

public static Date parseRFC822Date(String date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    private static final String TAG = "DateUtils";
    private static final String[] RFC822DATES = { "dd MMM yy HH:mm:ss Z", };
    private static ThreadLocal<SimpleDateFormat> RFC822Formatter = new ThreadLocal<SimpleDateFormat>() {
        @Override//  w w  w . j ava2 s . c  om
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(RFC822DATES[0], Locale.US);
        }

    };

    public static Date parseRFC822Date(String date) {
        Date result = null;
        if (date.contains("PDT")) {
            date = date.replace("PDT", "PST8PDT");
        }
        if (date.contains(",")) {
            // Remove day of the week
            date = date.substring(date.indexOf(",") + 1).trim();
        }
        SimpleDateFormat format = RFC822Formatter.get();
        for (int i = 0; i < RFC822DATES.length; i++) {
            try {
                format.applyPattern(RFC822DATES[i]);
                result = format.parse(date);
                break;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        if (result == null) {
            Log.e(TAG, "Unable to parse feed date correctly");
        }

        return result;
    }
}

Related

  1. convertToDate(String dateString)
  2. getDateFromString(String format, String dateString)
  3. getDateFromLJString( String dateString)
  4. getDateFromString(String dateString)
  5. parseRFC3339Date(String date)
  6. parseIcalDateToString(Date date, TimeZone tz)
  7. parseDate(String s)
  8. parseDate(String value)
  9. parseLastfmDate(String date)