Here you can find the source of toDate(String format, String str)
public static Date toDate(String format, String str)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat sdf = new SimpleDateFormat(); public static Date toDate(String format, String str) { Date date = null;//from w ww . j a v a 2 s .c o m if (format == null) { sdf.applyPattern("yyyy-MM-dd HH:mm:ss"); } else { sdf.applyPattern(format); } try { date = sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); } return date; } }