Here you can find the source of StringToDate(String dateStr)
public static Date StringToDate(String dateStr)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date StringToDate(String dateStr) { SimpleDateFormat sdf = null; Date date = null;/*from www . j a v a 2 s . c o m*/ if (dateStr.length() > 10) { if (dateStr.indexOf("T") > -1) { dateStr = dateStr.replace("T", " "); } sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } else { sdf = new SimpleDateFormat("yyyy-MM-dd"); } try { date = sdf.parse(dateStr); } catch (java.text.ParseException e) { e.printStackTrace(); return null; } return date; } }