Here you can find the source of convertToDate(String strDate, String format)
public static Date convertToDate(String strDate, String format)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date convertToDate(String strDate, String format) { if (strDate == null || format == null) { return null; }// w ww . j a va2 s . co m Date date = null; SimpleDateFormat sdf = new SimpleDateFormat(format); try { date = sdf.parse(strDate.trim()); } catch (ParseException e) { e.printStackTrace(); } return date; } }