Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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";
    public static final String[] RFC822DATES = { "dd MMM yy HH:mm:ss Z", };
    private static ThreadLocal<SimpleDateFormat> RFC822Formatter = new ThreadLocal<SimpleDateFormat>() {
        @Override
        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;
    }
}