Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static Date parseToDate(String dateString, String pattern) { if (pattern == null || "".equals(pattern)) { pattern = "yyyy-MM-dd HH:mm:ss"; } SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.getDefault()); try { return formatter.parse(dateString); } catch (ParseException e) { } return new Date(); } }