Here you can find the source of stringToDate(String dateString)
public static Date stringToDate(String dateString)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date stringToDate(String dateString) { String[] formatStrings = { "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd hh:mm", "yyyy-MM-dd" }; Integer i = 0;// w ww.ja v a 2 s . co m while (i < formatStrings.length) { try { return new SimpleDateFormat(formatStrings[i]) .parse(dateString); } catch (Exception e) { i++; } } return null; } }