Here you can find the source of toDate(String dateString, String format)
public static Date toDate(String dateString, String format)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date toDate(String str) { if (null == str || str.trim().isEmpty()) { return null; }// w ww . j a v a2 s. c o m try { DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmt.parse(str); } catch (ParseException e) { return null; } } public static Date toDate(String dateString, String format) { try { DateFormat fmt = new SimpleDateFormat(format); return fmt.parse(dateString); } catch (ParseException e) { return null; } } }