Java String to Date stringToDate(String string, String format)

Here you can find the source of stringToDate(String string, String format)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String string, String format) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static Date stringToDate(String string, String format) {
        Date dd = null;//from  w w  w  . ja va2  s .  co  m
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        try {
            dd = simpleDateFormat.parse(string.trim());
        } catch (Exception e) {
            dd = null;
        }
        return dd;
    }

    public static Date stringToDate(String string) {
        return stringToDate(string, DF_YMD);
    }
}

Related

  1. stringToDate(String strDate, String formartStr)
  2. stringToDate(String strDate, String oracleFormat)
  3. stringToDate(String strDate, String pattern)
  4. stringToDate(String strDate, String strFormat)
  5. stringToDate(String string)
  6. stringToDate(String text)
  7. StringToDate(String thisdate, Locale locale)
  8. stringToDate(String time, String format)
  9. stringToDate(String vStr, String vPatten)