Here you can find the source of toDate(String dateString)
public static Date toDate(String dateString)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date toDate(String dateString) { return parseDate(dateString); }// w ww. j a v a 2 s . com public static Date parseDate(String exifDate) { if (exifDate == null) { return null; } String patterns[]; int i; patterns = (new String[] { "yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "dd.MM.yy HH:mm", "yyyyMMdd HHmmss", "yyyyMMdd.HHmmss", "yyyyMMdd HHmm", "MM/dd/yy hh:mm a", "HH:mm:ss dd.MM.yyyy", "yyyy:MM:dd", "yyyy-MM-dd", "dd.MM.yy", "yyyyMMdd", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "MM/dd/yy", "yyyy:MM:dd HH:mm:sss" }); for (i = 0; i < patterns.length; i++) { try { DateFormat parser = new SimpleDateFormat(patterns[i]); return parser.parse(exifDate); } catch (ParseException ex) { } } return null; } public static Date parseDate(String date, String pattern) { if (date == null) return null; try { DateFormat parser = new SimpleDateFormat(pattern); return parser.parse(date); } catch (ParseException ex) { } return null; } public static String parseDate(Timestamp timestamp, String pattern) { if (timestamp == null) return null; DateFormat parser = new SimpleDateFormat(pattern); return parser.format(timestamp); } }