Here you can find the source of convertStrToDate(String s, String format)
public static Date convertStrToDate(String s, String format)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date convertStrToDate(String s) { try {//from w w w .ja v a 2 s.c o m DateFormat dateformat = DateFormat.getDateInstance(); Date date = dateformat.parse(s); return date; } catch (Exception exception) { exception.printStackTrace(); Calendar cal = Calendar.getInstance(); cal.set(1900, 0, 1); return cal.getTime(); } } public static Date convertStrToDate(String s, String format) { SimpleDateFormat simpledateformat = new SimpleDateFormat(format); try { Date date = simpledateformat.parse(s); return date; } catch (Exception exception) { exception.printStackTrace(); Calendar cal = Calendar.getInstance(); cal.set(1900, 0, 1); return cal.getTime(); } } }