Here you can find the source of parseToDate(String date, String format)
public static Date parseToDate(String date, String format) throws ParseException
//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 parseToDate(String date, String format) throws ParseException { if (date == null) return null; Date dDate = null;/*from www.j a va 2s. co m*/ if (format != null) { DateFormat formater = new SimpleDateFormat(format); dDate = formater.parse(date); } else { DateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); dDate = formater.parse(date); } return dDate; } }