Here you can find the source of stringConvertDate(String date)
public static Date stringConvertDate(String date)
//package com.java2s; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date stringConvertDate(String date) { if (null == date || "".equals(date)) { return null; }/* ww w.j a va2 s . c o m*/ if (date.length() == 10) {// yyyy-MM-dd date = date + " 00:00:00"; } else if (date.length() == 16) {// yyyy-MM-dd hh:mm date = date + ":00"; } SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Date objDate; try { objDate = formatter.parse(date); } catch (ParseException e) { objDate = null; } return objDate; } public static boolean equals(Timestamp t1, Timestamp t2) { if (t1 == null && t2 == null) { return true; } else { if (t1 == null) { return t2.equals(t1); } else { return t1.equals(t2); } } } }