Here you can find the source of strToDate(String dateStr, String format)
public static Date strToDate(String dateStr, String format) throws ParseException
//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 yyyyMMdd = "yyyyMMdd"; public static Date strToDate(String dateStr) throws ParseException { SimpleDateFormat formater = new SimpleDateFormat(yyyyMMdd); Date date = formater.parse(dateStr); return date; }//from w w w . j av a 2 s . c om public static Date strToDate(String dateStr, String format) throws ParseException { SimpleDateFormat formater = new SimpleDateFormat(format); Date date = formater.parse(dateStr); return date; } }