liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.cloud.attendance.utils;
 
import com.alibaba.fastjson.JSONObject;
import com.cloud.attendance.model.AttDay;
 
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class TimeTest {
 
    private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    private static SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd");
 
    public static void main(String[] args) throws ParseException {
//        long time = 5*60*1000;//5分钟
//        Date afterDate =sdfDate.parse(sdfTime.format(new Date())+" 15:11:30");//30分钟后的时间
       /* try {
            String inTime = "09:10:11";
            boolean matches = isTime(inTime);
            System.out.println("是否验证成功?"+(matches?"验证成功!~":"验证失败!~"));
            afterDate = new Date(sdf.parse("09:10:30").getTime() + time);
 
            String inTime2 = "09:10:11";
            String regex = "(20|21|22|23|[0-1]?\\\\d):[0-5]?\\\\d:[0-5]?\\\\d$";
            // 创建 Pattern 对象
            Pattern r = Pattern.compile(regex);
            // 现在创建 matcher 对象
            Matcher m = r.matcher(inTime2);
            boolean ms= m.matches();
            System.out.println(ms+"验证是否成功");
 
        }catch (ParseException e) {
            e.printStackTrace();
        }*/
      /*  Date beforeDate = new Date(System.currentTimeMillis() - time);//30分钟前的时间
 
//        System.out.println(sdf.format(afterDate ));
        System.out.println(sdf.format(beforeDate));
        System.out.println(beforeDate.before(afterDate));*/
 
 
 
/*String json1 = "{\"inTime\":\"2018-10-11 12:11:11\",\"inDeviceId\":\"121ds\",\"employeeId\":\"dd23edad\"}";
        JSONObject jsonObject = JSONObject.parseObject(json1);
        Date inTime = jsonObject.getDate("inTime");
        System.out.println(inTime);
        AttDay attDay = JSONObject.parseObject(json1, AttDay.class);
        System.out.println(attDay+"数据");*/
    Date beforeDate = sdfTime.parse("2018-12-17 18:00:00");
        System.out.println(beforeDate.after(new Date()));
    }
    public static boolean isTime(String time){
 
        Pattern p = Pattern.compile("((((0?[0-9])|([1][0-9])|([2][0-4]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
 
        return p.matcher(time).matches();
 
    }
}