判断输入日期格式是否为指定的格式,判断输入是否为数字

1. 指定日期格式    

String START_TIME ="2018-10-11";
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                try {
                         Date startT = format.parse(START_TIME);
                } catch (Exception e) {
                    e.getMessage();
                   System.out.println("日期格式输入错误");
                }

                  System.out.println("日期格式输入正确");

 将String类型的日期格式转换为Date类型,转换成功证明输入正确,报异常则输入错误

2.指定输入数字

               String MONTH_FEE ="5";
                Pattern pattern = Pattern.compile("[0-9]*");
                boolean matches = pattern.matcher(MONTH_FEE).matches();
                if(!matches){
                  System.out.println("必须填写数字");
                }

猜你喜欢

转载自blog.csdn.net/weixin_36205175/article/details/83244328