Here you can find the source of stringToDate(String string, String format)
public static Date stringToDate(String string, String format)
//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); } }