Here you can find the source of formatDate2Date(Date date, String format)
public static final Date formatDate2Date(Date date, String format)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final Date formatDate2Date(Date date, String format) { return formatString2Date(formatDate2String(date, format), format); }//from w w w .ja va2s . c o m public static final Date formatDate2Date(Date date, String format, Locale locale) { return formatString2Date(formatDate2String(date, format, locale), format, locale); } public static final Date formatString2Date(String dateString) { SimpleDateFormat sdf = new SimpleDateFormat(); Date datum = new Date(); try { datum = sdf.parse(dateString); return datum; } catch (ParseException e) { //logger.error(e.getMessage()); return null; } } public static final Date formatString2Date(String dateString, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); Date datum = new Date(); try { datum = sdf.parse(dateString); return datum; } catch (ParseException e) { //logger.error(e.getMessage()); return null; } } public static final Date formatString2Date(String dateString, String format, Locale locale) { SimpleDateFormat sdf = new SimpleDateFormat(format, locale); Date datum = new Date(); try { datum = sdf.parse(dateString); return datum; } catch (ParseException e) { //logger.error(e.getMessage()); return null; } } public static final String formatDate2String(Date date, String format) { if (isNull(date)) return null; SimpleDateFormat sdf = new SimpleDateFormat(format); String dateString = ""; try { dateString = sdf.format(date); } catch (Exception e) { //logger.error(e.getMessage()); } return dateString; } public static final String formatDate2String(Date date, String format, Locale locale) { if (isNull(date)) return null; SimpleDateFormat sdf = new SimpleDateFormat(format, locale); String dateString = ""; try { dateString = sdf.format(date); } catch (Exception e) { //logger.error(e.getMessage()); } return dateString; } public static final boolean isNull(Object str) { return (str == null || str.toString().trim().length() == 0); } }