Here you can find the source of toDate(String dateStr, String format)
public static Date toDate(String dateStr, String format) throws ParseException
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date toDate(String dateStr, String format) throws ParseException { return getSimpleDateFormat(format).parse(dateStr); }// w w w .j a v a2s . c om private static SimpleDateFormat getSimpleDateFormat(String strFormat) { if (strFormat != null && !"".equals(strFormat.trim())) { return new SimpleDateFormat(strFormat); } else { return new SimpleDateFormat(); } } }