Here you can find the source of stringToDate(String date)
public static final Date stringToDate(String date)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final Date stringToDate(String date) { if (date == null) { return null; }//from w w w . jav a2s. com String separator = String.valueOf(date.charAt(4)); String pattern = "yyyyMMdd"; if (!separator.matches("\\d*")) { pattern = "yyyy" + separator + "MM" + separator + "dd"; if (date.length() < 10) { pattern = "yyyy" + separator + "M" + separator + "d"; } } else if (date.length() < 8) { pattern = "yyyyMd"; } pattern += " HH:mm:ss.SSS"; pattern = pattern.substring(0, Math.min(pattern.length(), date.length())); try { return new SimpleDateFormat(pattern).parse(date); } catch (ParseException e) { return null; } } }