Here you can find the source of str2Date(String str)
public static java.sql.Date str2Date(String str)
//package com.java2s; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static java.sql.Date str2Date(String str) { if (str == null) return null; str = str.trim();//from ww w .j ava 2 s . c o m if (!str.matches("^\\d\\d\\d\\d-\\d\\d-\\d\\d$") && !str.matches("^\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d$")) return null; String[] ss = str.split("-| |:"); GregorianCalendar gc = new GregorianCalendar(); gc.set(Calendar.YEAR, Integer.parseInt(ss[0])); gc.set(Calendar.MONTH, Integer.parseInt(ss[1]) - 1); gc.set(Calendar.DAY_OF_MONTH, Integer.parseInt(ss[2])); if (ss.length == 6) { gc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(ss[3])); gc.set(Calendar.MINUTE, Integer.parseInt(ss[4])); gc.set(Calendar.SECOND, Integer.parseInt(ss[5])); } return new java.sql.Date(gc.getTimeInMillis()); } }