Java Date Parse convertStringToDate(String dt)

Here you can find the source of convertStringToDate(String dt)

Description

convert String To Date

License

Apache License

Declaration

public static Date convertStringToDate(String dt) 

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 {

    public static Date convertStringToDate(String dt) {
        if (dt == null || dt.equals("")) {
            return null;
        }/*from w  ww .j  a  v  a 2 s  .  c o  m*/
        return convertStringToDate("yyyy-MM-dd", dt);
    }

    public static Date convertStringToDate(String style, String dt) {
        if (dt == null || dt.equals("")) {
            return null;
        }
        if (style == null || style.equals("")) {
            style = "yyyy-MM-dd";
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(style);
        dateFormat.setLenient(false);
        try {
            return dateFormat.parse(dt);
        } catch (ParseException ex) {
            return null;
        }

    }
}

Related

  1. convertStringToDate(String dateString, String dateFormat)
  2. convertStringToDate(String dateString, String pattern)
  3. convertStringToDate(String dateText)
  4. convertStringToDate(String dateTime)
  5. convertStringToDate(String dateTime)
  6. convertStringToDate(String input)
  7. convertStringToDate(String s)
  8. convertStringToDate(String str)
  9. convertStringToDate(String str, String pattern)