Here you can find the source of stringToDate(String date)
public static Date stringToDate(String date)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String DATE_PARTTEN = "yyyy-MM-dd"; public static Date stringToDate(String date) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_PARTTEN); Date d = null;/*from ww w . ja v a2 s. c o m*/ try { String[] datesl = new String[3]; if (date.contains("-")) { datesl = date.split("-"); } else if (date.contains("/")) { datesl = date.split("/"); } if (datesl[1].length() == 1) { datesl[1] = "0" + datesl[1]; } if (datesl[2].length() == 1) { datesl[2] = "0" + datesl[2]; } d = sdf.parse(datesl[0] + "-" + datesl[1] + "-" + datesl[2]); } catch (ParseException e) { e.printStackTrace(); } return d; } }