Java Date Parse convertStringToDate(String str, String pattern)

Here you can find the source of convertStringToDate(String str, String pattern)

Description

convert String To Date

License

Apache License

Declaration

public static Date convertStringToDate(String str, String pattern) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String patternDate = "yyyy-MM-dd";

    public static Date convertStringToDate(String str, String pattern) {
        SimpleDateFormat sdf = null;
        try {//from   ww  w  .jav  a  2  s  . co  m
            sdf = new SimpleDateFormat(pattern);
        } catch (Exception ex) {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        try {
            return sdf.parse(str);
        } catch (Exception e) {
        }
        return null;
    }

    public static Date parse(String param) {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(patternDate);
        try {
            date = sdf.parse(param);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return date;
    }
}

Related

  1. convertStringToDate(String dateTime)
  2. convertStringToDate(String dt)
  3. convertStringToDate(String input)
  4. convertStringToDate(String s)
  5. convertStringToDate(String str)
  6. convertStringToDate(String str_date)
  7. convertStringToDate(String strDate)
  8. convertStringToDate(String strDate, String parseFormat)
  9. convertStringToDate(String stringDate, String pattern)