package de.eknori.ssjsplus.javascript; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class DateHelper { /** * @author Ulrich krause * @since 2012/05/06 * @return true/false Boolean */ public boolean isValidDate(String dt) { if (dt == null) return false; // set the format to use as a constructor argument SimpleDateFormat dateFormat = new SimpleDateFormat( this.getDateFormatPattern()); if (dt.trim().length() != dateFormat.toPattern().length()) return false; dateFormat.setLenient(false); try { // parse the inDate parameter dateFormat.parse(dt.trim()); } catch (ParseException pe) { return false; } return true; } /** * @author Ulrich krause * @since 2012/05/06 * @return DateFormatPattern String (i.e. yyyy/MM/dd ) */ public String getDateFormatPattern() { SimpleDateFormat df = (SimpleDateFormat) DateFormat .getDateInstance(DateFormat.MEDIUM); return df.toPattern(); } }