Java String to Date strToDate(String strD)

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

Description

Convert string to date object

License

Open Source License

Parameter

Parameter Description
strD the string date format:yyyy-MM-dd HH:mm:ss

Declaration

public static Date strToDate(String strD) 

Method Source Code


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

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

public class Main {
    /**//from w  w  w .j  a v a 2s.co  m
     * Convert string to date object
     * 
     * @param strD
     *            the string date format:yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static Date strToDate(String strD) {
        try {
            String strFormat = "yyyy-MM-dd   HH:mm:ss";
            SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
            return sdf.parse(strD);
        } catch (java.text.ParseException e) {
            return new Date();
        }
    }
}

Related

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