2020 年 6 月 19 日 12:45:34 更新
676 人次浏览
以下示例演示如何使用 String 类的 matches 方法验证日期是否为正确的格式。示例实时演示public class Main { public static void main(String[] argv) { boolean isDate = false; String date1 = "8-05-1988"; String date2 = "08/04/1987"; String datePattern = "\d{1, 2}-\d{1, 2}-\d{4}"; isDate = date1.matches(datePattern); System.out.println("Date :"+ date1+": matches with the this date Pattern:"+datePattern+"Ans:"+isDate); isDate = date2.matches(datePattern); System.out.println("Date :"+ date2+": matches with the this date ... 阅读更多