java正则表达式判断日期

  public static void main(String[] args) {

        String pattern ="\\d{4}(\\-|\\/|.)\\d{1,2}\\1\\d{1,2}";
        //  应收日期 2019/1/1
        // 2019-01-02
        // 2019.02.02
        // 20190909

        boolean isMatchDate1 = Pattern.matches(pattern, "2019-01-02");
        boolean isMatchDate2 = Pattern.matches(pattern, "2019/1/1");
        boolean isMatchDate3 = Pattern.matches(pattern, "2019.02.02");
        boolean isMatchDate4 = Pattern.matches(pattern, "20190909");
        System.out.println("字符串中是否是日期' 子字符串? " + isMatchDate1+";"+isMatchDate2+";"+isMatchDate3+";"+isMatchDate4+";");


    }

字符串中是否是日期’ 子字符串? true;true;true;true;

你可能感兴趣的:(java)