Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static void main(String[] args) {
        System.out.println("isValid - dd/MM/yyyy with 20150925 = " + isValidFormat("dd/MM/yyyy", "20150925"));
        System.out.println("isValid - dd/MM/yyyy with 25/09/2015 = " + isValidFormat("dd/MM/yyyy", "25/09/2015"));
    }

    public static boolean isValidFormat(String format, String value) {
        Date date = null;
        try {
            date = new SimpleDateFormat(format).parse(value);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return date != null;
    }

}