Java Parse Date parseDate(String datestr)

Here you can find the source of parseDate(String datestr)

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String datestr) 

Method Source Code

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

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

import java.util.Locale;

public class Main {

    public static Date parseDate(String datestr) {
        if (null == datestr || "".equals(datestr)) {
            return null;
        }/* w  w  w  . j  a v  a 2s  . c o  m*/
        try {
            String fmtstr = null;
            if (datestr.indexOf(':') > 0) {
                fmtstr = "yyyy-MM-dd HH:mm:ss";
            } else {

                fmtstr = "yyyy-MM-dd";
            }
            SimpleDateFormat sdf = new SimpleDateFormat(fmtstr, Locale.UK);
            return sdf.parse(datestr);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. parseDate(String date, String pattern, TimeZone zone)
  2. parseDate(String dateAsString)
  3. parseDate(String dateAsString)
  4. parseDate(String dateFormat, String value)
  5. parseDate(String dateOfString, String targetFormat)
  6. parseDate(String dateStr)
  7. parseDate(String dateStr)
  8. parseDate(String dateStr)
  9. parseDate(String dateStr)