Here you can find the source of getDateFromString(String date, String pattern)
public static Date getDateFromString(String date, String pattern) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static Map<String, SimpleDateFormat> formats = new HashMap(); public static Date getDateFromString(String date, String pattern) throws ParseException { SimpleDateFormat sDateFormat = getDateFormat(pattern); synchronized (sDateFormat) { return sDateFormat.parse(date); }// w ww. j av a 2 s . com } public static SimpleDateFormat getDateFormat(String pattern) { SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern); if (sDateFormat == null) { sDateFormat = new SimpleDateFormat(pattern); formats.put(pattern, sDateFormat); } return sDateFormat; } }