Java Parse Date parseDate(DateFormat df, String dateStr)

Here you can find the source of parseDate(DateFormat df, String dateStr)

Description

parse date as ET or UTC

License

Open Source License

Declaration

protected static Date parseDate(DateFormat df, String dateStr) 

Method Source Code


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

import java.text.DateFormat;
import java.util.*;

public class Main {
    private static final TimeZone ET = TimeZone.getTimeZone("US/Eastern");

    /**/*  w w w .  j a v  a 2  s. c  om*/
     * parse date as ET or UTC
     */
    protected static Date parseDate(DateFormat df, String dateStr) {
        Date date = null;
        if (dateStr != null && dateStr.length() > 0) {
            try {
                if (dateStr.contains("UTC")) {
                    date = df.parse(dateStr);
                } else if (dateStr.contains("ET")) {
                    // parse as winter time
                    date = df.parse(dateStr.replace("ET", "EST"));
                    // EDT - summer, EST - winter
                    // daylight savings is summer time
                    if (ET.inDaylightTime(date)) {
                        // reparse as summer time
                        date = df.parse(dateStr.replace("ET", "EDT"));
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //System.out.println("date " + dateStr + " -> " + date);
        }
        return date;
    }
}

Related

  1. parseDate(Date date)
  2. parseDate(Date date)
  3. parseDate(Date date, int style, Locale local, boolean withTime)
  4. parseDate(Date date, String format)
  5. parseDate(Date date, String pattern)
  6. parseDate(DateFormat f, String date)
  7. parseDate(final Date date)
  8. parseDate(final String date)
  9. parseDate(final String date)