Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DateValidator class in Java which will validate dates
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateValidator {
public boolean isThisDateValid(String dateToValidate, String dateFromat) {
if (dateToValidate == null) {
return false;
SimpleDateFormat sdf = new SimpleDateFormat(dateFromat);
try {
// If not valid, it will throw ParseException
Date date = sdf.parse(dateToValidate);
} catch (ParseException e) {
return false;
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment