Here you can find the source of parseDateTime(String dateTimeStr)
public static Date parseDateTime(String dateTimeStr)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Pattern; public class Main { private final static Pattern DATE_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d?-\\d\\d?"); private final static Pattern DATETIME_PATTERN = Pattern .compile("\\d\\d\\d\\d-\\d\\d?-\\d\\d?T\\d\\d?:\\d\\d?:\\d\\d?"); private final static String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; private final static String DATETIME_FORMAT_NoT = "yyyy-MM-dd HH:mm:ss"; public static Date parseDateTime(String dateTimeStr) { if (dateTimeStr.contains("00:00T")) { dateTimeStr = dateTimeStr.replaceFirst("00:00T", ""); }/*w w w. ja v a 2 s. c om*/ try { if (isValidDateTimeString(dateTimeStr)) { return (new SimpleDateFormat(DATETIME_FORMAT).parse(dateTimeStr)); } else if (isValidDateString(dateTimeStr)) { return (new SimpleDateFormat(DATETIME_FORMAT).parse(dateTimeStr.concat("T00:00:00"))); } else { return (new SimpleDateFormat(DATETIME_FORMAT_NoT).parse(dateTimeStr)); } } catch (ParseException e) { throw new IllegalArgumentException("Invalid datetime format: " + dateTimeStr, e); } } public static boolean isValidDateTimeString(String dateTimeStr) { return dateTimeStr == null ? false : DATETIME_PATTERN.matcher(dateTimeStr).matches(); } public static boolean isValidDateString(String dateStr) { return dateStr == null ? false : DATE_PATTERN.matcher(dateStr).matches(); } }