Here you can find the source of parseDate(String dateOfString, String targetFormat)
public static Date parseDate(String dateOfString, String targetFormat)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date parseDate(String dateOfString, String targetFormat) { if (dateOfString == null || dateOfString.trim().equals("")) { return null; }//from w ww . ja va 2 s. co m if (dateOfString != null && dateOfString.length() > 19) { dateOfString = dateOfString.substring(0, 19); } // String format = DateUtil.getPattern(targetFormat); if (targetFormat == null) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(targetFormat); Date date = null; try { date = simpleDateFormat.parse(dateOfString); simpleDateFormat = new SimpleDateFormat(targetFormat); date = simpleDateFormat.parse(simpleDateFormat.format(date)); } catch (ParseException e) { e.printStackTrace(); } return date; } }