Java tutorial
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static boolean validTime(String str, String pattern) { DateFormat formatter = new SimpleDateFormat(pattern, Locale.ENGLISH); Date date = null; try { date = (Date) formatter.parse(str); } catch (ParseException e) { return false; } return str.equals(formatter.format(date)); } }