Java String to Date strToDate(String str)

Here you can find the source of strToDate(String str)

Description

str To Date

License

Open Source License

Declaration

public static Date strToDate(String str) 

Method Source Code


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

public class Main {

    public static Date strToDate(String str) {
        if (isEmpty(str)) {
            return null;
        }//from  www . j a  va 2  s. c o  m
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if (str.length() != 19) {
                return null;
            }
            return dateFormat.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }

    public static boolean isEmpty(String str) {
        return ((str == null) || (str.length() == 0));
    }
}

Related

  1. strToDate(String dateStr, String format)
  2. strToDate(String format, String dateStr)
  3. strToDate(String i_StrDate, String i_Format)
  4. strToDate(String input, String format)
  5. strToDate(String s, Date defaultValue)
  6. strToDate(String str, String format, java.util.Date defaultValue)
  7. strToDate(String strD)
  8. strToDate(String strDate)
  9. strToDate(String strDate)