Here you can find the source of StringtoDate(String dateStr, String format)
public static java.util.Date StringtoDate(String dateStr, String format)
//package com.java2s; //License from project: Apache License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static java.util.Date StringtoDate(String dateStr, String format) { Date d = null;//from w ww .ja v a2s . c om SimpleDateFormat formater = new SimpleDateFormat(format); try { formater.setLenient(false); d = formater.parse(dateStr); } catch (Exception e) { // log.error(e); d = null; } return d; } public static java.util.Date StringtoDate(String dateStr, String format, ParsePosition pos) { Date d = null; SimpleDateFormat formater = new SimpleDateFormat(format); try { formater.setLenient(false); d = formater.parse(dateStr, pos); } catch (Exception e) { // log.error(e); d = null; } return d; } }