Here you can find the source of stringToDate(String dateStr)
public static Date stringToDate(String dateStr)
//package com.java2s; //License from project: Educational Community License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd"); /**/* w ww . ja v a 2 s . com*/ * Converts a String with format DateUtils.DATE_FORMAT to a Date. * Returns null if the parse fails. */ public static Date stringToDate(String dateStr) { if (dateStr == null) return null; try { return DATE_FORMAT.parse(dateStr); } catch (ParseException ex) { return null; } } }