[JAVA] 날짜를 입력받아 현재 날짜와 비교

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
        /**
          * 현재 날짜와 크기 비교함.
          * * 비교 날짜가 현재 날짜보다 클 경우 Y,
          * * 비교 날짜가 현재날짜보다 작을 경우 N
          * * 비교 날짜가 현재날짜와 같을 경우 E
          * @param comDate
          * @return
          */
         public static String compareDate(String comDate) {
                String regiValue = "N";
                
                String tmp; 
                
                tmp = comDate.replaceAll("-""");
                tmp = comDate.replaceAll("//.""");       
                tmp = comDate.replaceAll(":""");
                tmp = comDate.replaceAll("\\[""");
                tmp = comDate.replaceAll("\\]""");
                tmp = comDate.replaceAll(" """);
                 
                SimpleDateFormat nowDate = new SimpleDateFormat("yyyyMMdd");
                
                if(tmp.length() > 8) nowDate = new SimpleDateFormat("yyyyMMddHHmm");
                
                Date now = new Date();
 
                try {
                     
                    Date com =  nowDate.parse(tmp);
                     
                    if(com.getTime() > now.getTime()){
                        regiValue = "Y";
                    } else if(com.getTime() < now.getTime()) {
                        regiValue = "N";
                    } else {
                        regiValue = "E";
                    }
                 } catch (Exception e) {
                     System.out.println(e.toString()); 
                 }
                 return regiValue;
             }
cs

포맷 형식은 상황에 맞게 바꾸어 쓰시면 됩니다.

이정도 소스는 설명이 필요없쥬~?

 

반응형