Here you can find the source of stringToDate(String dateString)
public static Date stringToDate(String dateString)
//package com.java2s; import java.text.ParsePosition; import java.text.SimpleDateFormat; public class Main { public static Date stringToDate(String dateString) { if (dateString == null || dateString.trim().length() == 0) return null; String datestr = dateString.trim(); String sf = "yyyy-MM-dd HH:mm:ss"; Date dt = stringToDate(datestr, sf); if (dt == null) dt = stringToDate(datestr, "yyyy-MM-dd"); if (dt == null) dt = stringToDate(datestr, "yyyyMMdd"); return dt; }/* w ww . j a v a 2 s . c o m*/ public static Date stringToDate(String dateString, String sf) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat sdf = new SimpleDateFormat(sf); Date dt = sdf.parse(dateString, pos); return dt; } }