Here you can find the source of getDateFromString(String date, String fmt)
public static Date getDateFromString(String date, String fmt) throws Exception
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; public static Date getDateFromString(String date, String fmt) throws Exception { if (date == null || date.trim().length() == 0) return null; SimpleDateFormat sdf = fmt == null ? new SimpleDateFormat(DEFAULT_DATE_FORMAT) : new SimpleDateFormat(fmt); return sdf.parse(date); }/*from w w w .j a v a2 s. co m*/ public static Date parse(String date, String format) throws ParseException { if (date == null) return null; SimpleDateFormat fmt = new SimpleDateFormat(format); return fmt.parse(date); } }