Here you can find the source of toDate(final String dateString, final String format)
public static Date toDate(final String dateString, final String format) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class Main { private static final Map<String, SimpleDateFormat> sdfs = new ConcurrentHashMap<String, SimpleDateFormat>(); public static Date toDate(final String dateString, final String format) throws ParseException { if (dateString == null || dateString.isEmpty()) { return null; }// w w w .j a va2 s . co m final SimpleDateFormat sdf = getSimpleDateFormat(format); Date date = null; if (dateString != null) { date = sdf.parse(dateString); } return date; } public static boolean isEmpty(final String string) { return string == null || string.trim().length() == 0; } private static SimpleDateFormat getSimpleDateFormat(final String format) { SimpleDateFormat sdf = sdfs.get(format); if (sdf == null) { sdf = new SimpleDateFormat(format); sdfs.put(format, sdf); } return sdf; } }