Here you can find the source of parse(String str)
public static Date parse(String str)
//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 String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_PATTERN = "yyyy-MM-dd"; public static Date parse(String str, String formatPattern) { try {//from w w w . ja va 2 s. c o m return new SimpleDateFormat(formatPattern).parse(str); } catch (ParseException e) { throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = " + new SimpleDateFormat(formatPattern).toPattern(), e); } } public static Date parse(String str) { if (str.length() != DATE_PATTERN.length() && str.length() != DATE_TIME_PATTERN.length()) { return null; } String formatPattern = DATE_PATTERN; if (str.length() > 10) { formatPattern = DATE_TIME_PATTERN; } try { return new SimpleDateFormat(formatPattern).parse(str); } catch (ParseException e) { throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = " + new SimpleDateFormat(formatPattern).toPattern(), e); } } }