Java Parse Date parseDate(Object str)

Here you can find the source of parseDate(Object str)

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(Object str) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
            "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss",
            "yyyy.MM.dd HH:mm", "yyyy.MM" };

    public static Date parseDate(Object str) {
        if (str == null) {
            return null;
        }/*from   w w  w.ja va2 s . co  m*/
        try {
            return new SimpleDateFormat(parsePatterns[0]).parse(str.toString());
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. parseDate(final String str, final Locale locale, final String... parsePatterns)
  2. parseDate(final String value)
  3. parseDate(Long date, String format)
  4. parseDate(Map obj, String field, String format)
  5. parseDate(Object o)
  6. parseDate(Object val)
  7. parseDate(SimpleDateFormat parser, String str, String[] parsePatterns)
  8. parseDate(String _dateString)
  9. parseDate(String actual, DateFormat format, Pattern pattern)