1 package com.ztwywy.test;
 2 
 3 import java.util.regex.Matcher;
 4 import java.util.regex.Pattern;
 5 
 6 public class ZhengZe {
 7 
 8     public static void main(String[] args) {
 9         //
10         Pattern p = Pattern.compile("(\\d{4})-(\\d{1,2})-(\\d{1,2})");
11         Matcher m = p.matcher("admin.add.sss.2017-07-20");
12 
13         if (m.find()) {
14             System.out.println("日期:" + m.group());
15             System.out.println("年:" + m.group(1));
16             System.out.println("月:" + m.group(2));
17             System.out.println("日:" + m.group(3));
18         }
19     }
20 
21     public boolean isDate(String date) {
22         /**
23          * 判断日期格式和范围
24          */
25         String rexp = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
26 
27         Pattern pat = Pattern.compile(rexp);
28 
29         Matcher mat = pat.matcher(date);
30 
31         boolean dateType = mat.matches();
32 
33         return dateType;
34     }
35 
36 }

啊....看看创号的日期,都过去4年9个月了,当初只是想在ACM的道路上走得更远,中间因为一些原因放弃了,但是并不影响我对程序的执着,换个环境我觉得更自由,大概没有当初那么多烧脑的问题和逻辑,不过我确实更喜欢现在这种可以根据现场问题随时更改程序规则生活