Here you can find the source of formatStrToDate(String strDate, int format)
public final static java.util.Date formatStrToDate(String strDate, int format)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { private final static SimpleDateFormat[] DATE_FORMATTER = new SimpleDateFormat[] { new SimpleDateFormat("MMM d, yyy"), new SimpleDateFormat("EEE, MMM d, yyyy"), new SimpleDateFormat("MMM d, yyyy HH:mm:ss"), new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss"), new SimpleDateFormat("yyyy/MM/dd"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") }; public final static java.util.Date formatStrToDate(String strDate, int format) { java.util.Date rel = null; if (strDate != null && !strDate.equals("")) { if (format >= DATE_FORMATTER.length || format < 0) { format = 0;//from ww w . ja v a 2 s . c o m } try { rel = DATE_FORMATTER[format].parse(strDate); } catch (ParseException e) { rel = null; } } return rel; } }