Here you can find the source of stringToDate(String time, String format)
public static Date stringToDate(String time, String format)
//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 time, String format) { try {//from w w w. j a v a 2 s . c o m SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(time); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } public static Date parse(String strDate, String format) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(strDate); } }