Java tutorial
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date stringToDate(String dateStr, String formatStr) { DateFormat sdf = new SimpleDateFormat(formatStr); Date date = null; try { date = sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); } return date; } public static Date stringToDate(String mFirstDate, SimpleDateFormat yearformat) { Date parse = null; try { if (mFirstDate != null) { parse = yearformat.parse(mFirstDate); } } catch (ParseException e) { e.printStackTrace(); } return parse; } }