Here you can find the source of toDate(String string, String format)
public static Date toDate(String string, String format)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date toDate(String string, String format) { DateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setLenient(true);/* w ww . j a va 2 s . com*/ Date d; try { d = dateFormat.parse(string); } catch (ParseException pe) { throw new IllegalArgumentException(pe); } return d; } }