Here you can find the source of isDateTime(String dateTime)
public static boolean isDateTime(String dateTime)
//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 boolean isDateTime(String dateTime) { int first = dateTime.indexOf(":"); int last = dateTime.lastIndexOf(":"); if (first == -1) { return false; }/*from w w w. ja v a 2s .c om*/ SimpleDateFormat df = null; if (first == last) { df = new SimpleDateFormat("yyyy-MM-dd hh:mm"); } else { df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); } Date date = null; try { date = df.parse(dateTime); } catch (ParseException e) { return false; } return date == null; } }