Here you can find the source of parseStringForDate(String dateString)
private static Date parseStringForDate(String dateString)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static Date parseStringForDate(String dateString) { //Since there is no way to know the TimeZone of the document, will assume the time zone of the end-user. String[] dateFormats = new String[] { "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" }; for (int i = 0; i < dateFormats.length; i++) { Date date = attemptParse(dateString, dateFormats[i]); if (date != null) { return date; }//from w w w . j a v a2 s . c om } return null; } /** * An attempt to parse the dateString. Will return null if it cannot be parsed. * @param dateString * @param dateFormat * @return */ private static Date attemptParse(String dateString, String dateFormat) { try { SimpleDateFormat format; if (dateFormat != null) { format = new SimpleDateFormat(dateFormat); } else { format = new SimpleDateFormat(); } Date parsedDate = format.parse(dateString); return parsedDate; } catch (ParseException e) { ; } return null; } }