check Date MMDD format - Java java.util

Java examples for java.util:Date Format

Description

check Date MMDD format

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String expireDate = "java2s.com";
        System.out.println(checkDateMMDD(expireDate));
    }//  w  ww. j  a v a  2  s .co  m

    public static boolean checkDateMMDD(String expireDate) {
        if (expireDate != null && expireDate.length() == 4) {
            int month = Integer.parseInt(expireDate.substring(0, 2));
            int day = Integer.parseInt(expireDate.substring(2));
            if (month >= 1 && month <= 12) {
                if (day >= 1 && day <= 31) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else
            return false;
    }
}

Related Tutorials