Here you can find the source of stringToDate(String date, String format)
public static Date stringToDate(String date, String format) throws Exception
//package com.java2s; //License from project: Apache License import java.util.Date; import java.text.SimpleDateFormat; import java.text.ParseException; public class Main { public static Date stringToDate(String date, String format) throws Exception { Date d = null;/*www . ja v a 2 s .c o m*/ try { SimpleDateFormat formatter = new SimpleDateFormat(format); d = formatter.parse(date); if (!formatter.format(d).equals(date)) { throw new Exception("error format date"); } } catch (ParseException e) { throw e; } return d; } }