본문으로 바로가기

자바 날짜 값 구하기(현재, 어제, 한시간 전)

category JAVA 2019. 10. 8. 13:37
반응형

 

SimpleDateFormat 은 자유자재로 설정하시면됩니다

 

현재 저같은경우 20191008 000000

만약 SimpleDateFormat("yyyy-MM-dd" HH:mm:ss"); 설정할 경우

2019-10-08 00:00:00 으로 나오게 됩니다

참고하시면 되요!

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
/***********************************************************************
     * 현재시간 가져오기
     * 
     * @return
     * *********************************************************************/
    public String fn_time() 
    {
    
    SimpleDateFormat Format = new SimpleDateFormat("yyyyMMdd HHmmss");
    Date time = new Date();
    
    String timedata = Format.format(time).toString();
    
    return timedata;
    
    }
 
 
/***********************************************************
     * 어제시간 가져오기
     * 
     * @return
     *********************************************************/
    public String fn_Yesterday() {
        SimpleDateFormat Format = new SimpleDateFormat("yyyyMMdd HH");
        Calendar cal = Calendar.getInstance();
 
        cal.add(Calendar.DATE, -1);
        String timedate = Format.format(cal.getTime());
 
        return timedate;
    }
 
/***********************************************************************
     *  
     * 
     * @return
     *********************************************************************/
    public String fn_time() {
 
        SimpleDateFormat Format = new SimpleDateFormat("yyyyMMdd HHmmss");
        Date time = new Date();
 
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.HOUR, -1);
        String timedata = Format.format(cal.getTime()).toString();
        return timedata;
 
    }
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

반응형