Here you can find the source of stringToDate(String dateString, String dataFormat)
public static Date stringToDate(String dateString, String dataFormat)
//package com.java2s; import java.util.Date; public class Main { public static Date stringToDate(String dateString, String dataFormat) { if (isEmpty(dateString)) { return null; }//from ww w.ja v a 2s . c om if (dateString.length() != 14) { return null; } java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(dataFormat); try { return dateFormat.parse(dateString); } catch (Exception ex) { ex.printStackTrace(); } return null; } public static boolean isEmpty(String input) { return (input == null || input.length() == 0); } }