Here you can find the source of strToDate(String strDate)
public static final Date strToDate(String strDate)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String dtSimple = "yyyy-MM-dd"; public static final String simpleFormat = "yyyy-MM-dd HH:mm"; public static final Date strToDate(String strDate) { if (strToSimpleFormat(strDate) != null) { return strToSimpleFormat(strDate); } else {/*w w w . j a v a 2 s . c om*/ return strToDtSimpleFormat(strDate); } } public static final Date strToSimpleFormat(String strDate) { if (strDate == null) { return null; } try { return getFormat(simpleFormat).parse(strDate); } catch (Exception e) { } return null; } public static final Date strToDtSimpleFormat(String strDate) { if (strDate == null) { return null; } try { return getFormat(dtSimple).parse(strDate); } catch (Exception e) { } return null; } public static final Date strToDtSimpleFormat(String strDate, String pattern) { if (strDate == null) { return null; } try { return getFormat(pattern).parse(strDate); } catch (Exception e) { } return null; } private static final DateFormat getFormat(String format) { return new SimpleDateFormat(format); } }