标准字符集合-自定义集合-量词{}

@Test
public void convert() {
        String s ="2021/11/11";
    String sdf = null;
    if (Pattern.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", s)) {
        sdf = s;
    }
    else if (Pattern.matches("^\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}$", s)){
        sdf = s;
    }
    else if (Pattern.matches("^\\d{4}/\\d{2}/\\d{2}$", s)){
        sdf = s;
    }
    else if (Pattern.matches("^\\d{4}-\\d{2}/-\\d{2}}$", s)){
        sdf = s;
    }


    System.out.println(sdf);

}

猜你喜欢

转载自blog.csdn.net/wqr111/article/details/118398000