반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

디케이

[java] 날짜 더하기 Canlendar 클래스 getInstance() 메소드 사용 본문

Java

[java] 날짜 더하기 Canlendar 클래스 getInstance() 메소드 사용

디케이형 2021. 1. 30. 04:13
반응형
//6개월 뒤 날짜 계산

SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //날짜 포멧	
Date time = new Date();	 //현재 날짜
Calendar cal = Calendar.getInstance();	 //날짜 계산을 위해 Calendar 추상클래스 선언 getInstance()메소드 사용	
cal.setTime(time);	
cal.add(Calendar.MONTH, 6);	//6개월 더하기
String date = simpleDate.format(cal.getTime());

 

// 1시간 전 계산
cal.add(Calender.HOUR, -1)

// 1일 전 계산
cal.add(Calender.DATE, -1)
반응형