Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {

    public static boolean isValidDate(String inDate) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        try {
            dateFormat.parse(inDate.trim());
        } catch (ParseException pe) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {

        System.out.println(isValidDate("2004-02-29"));
        System.out.println(isValidDate("2005-02-29"));
    }
}
/*
true
false
*/