Here you can find the source of toDate(String date, String format)
public static Date toDate(String date, String format)
//package com.java2s; //License from project: LGPL import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date toDate(String date, String format) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 0);/*ww w . ja va 2s . co m*/ c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.HOUR, 12); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); SimpleDateFormat sdf = new SimpleDateFormat(format); Date d; try { d = sdf.parse(date); } catch (ParseException e) { throw new IllegalArgumentException("unable to parse date from [" + date + "]", e); } c.setTimeInMillis(d.getTime()); // log.debug("Parsed ["+c.getTime()+"] from ['"+date+"','"+format+"']"); Date dateType = c.getTime(); assert null != dateType; return dateType; } }