Here you can find the source of stringToDate(String dateString, String pattern)
public static Date stringToDate(String dateString, String pattern)
//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 Date stringToDate(String dateString) { return stringToDate(dateString, "yyyy-MM-dd HH:mm:ss"); }/*from w w w . ja v a 2 s.c o m*/ public static Date stringToDate(String dateString, String pattern) { SimpleDateFormat simpledateformat = new SimpleDateFormat(pattern); Date date = new Date(); try { date = simpledateformat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; } }