Here you can find the source of getTimeFromString(String timeStr, String format)
public static Date getTimeFromString(String timeStr, String format)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String FORMAT_DATE_TIME = "yyyy-MM-dd hh:mm"; private static SimpleDateFormat sdf = new SimpleDateFormat(); public static Date getTimeFromString(String timeStr, String format) { if (format == null || format.trim().equals("")) { sdf.applyPattern(FORMAT_DATE_TIME); } else {/*from ww w.j a v a 2s .c o m*/ sdf.applyPattern(format); } try { return sdf.parse(timeStr); } catch (ParseException e) { return new Date(); } } }