Here you can find the source of stringToDate(String src, String format)
public static java.util.Date stringToDate(String src, String format)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static final String VN_DATE_FORMAT = "dd/MM/yyyy"; public static java.util.Date stringToDate(String src, String format) { try {/*from w ww . j ava 2 s .com*/ src = src.trim(); if (format == null) format = VN_DATE_FORMAT; SimpleDateFormat ts = new SimpleDateFormat(format); return ts.parse(src); } catch (Exception e) { // System.out.println("Time Error:>"+src+"="+format+"<"); // e.printStackTrace(); return null; } } public static java.util.Date parse(String src) { try { return DateFormat.getDateInstance().parse(src); } catch (ParseException e) { return DateFormat.getInstance().getCalendar().getTime(); } } }