Java Parse Date Pattern YYYY parseVariuosDateTime(String dateStr)

Here you can find the source of parseVariuosDateTime(String dateStr)

Description

parse Variuos Date Time

License

Open Source License

Declaration

public static Date parseVariuosDateTime(String dateStr) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Main {
    public static Date parseVariuosDateTime(String dateStr) {
        // Preparation
        int i = dateStr.indexOf('(');
        if (i >= 0) {
            dateStr = dateStr.substring(0, i);
        }//from w  w w  . j a v  a  2 s .  c o  m

        SimpleDateFormat dateFormat;
        List<String> patterns = new ArrayList<String>();
        patterns.add("MM/dd HH:mm:ss");
        patterns.add("MM/dd HH:mm");
        patterns.add("MM/dd/yyyy HH:mm:ss");
        patterns.add("MM/dd/yyyy HH:mm");
        patterns.add("dd-MM-yyyy HH:mm");
        patterns.add("dd-MM-yyyy HH:mm:ss");
        Date res = null;
        for (String pattern : patterns) {
            dateFormat = new SimpleDateFormat(pattern);
            try {
                res = dateFormat.parse(dateStr);
            } catch (ParseException e) {

            }
        }
        return res;
    }
}

Related

  1. parseToString(final Date date, final String format)
  2. parseToStringDate(long ms)
  3. parseTwitterDate(String theDate)
  4. parseUserDate(String date)
  5. parseUsGeneralDateTime(Date value)
  6. parseW3CDate(String dateString)
  7. parseW3CDateRobust(String dateString)
  8. parseW3CDateTime(String date)
  9. parseW3CDateTime(String sDate, Locale locale)