티스토리 뷰
@RequestParam(defaultValue = "-1") String selectday) 에서 선택한 날짜를 받아온 string 타입 값을 자바 컨트롤단에서 하루 일자 더하기.
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = null;
try {
date = dateFormat.parse(selectday); //pts.js 파일에서 받아온 selectday 데이터 값
} catch (Exception e) {
// TODO: handle exception
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 1); // 하루 일자를 더한다.
System.out.println("date : " + date);
System.out.println(cal.getTime());
String tomorrow = dateFormat.format(cal.getTime());
System.out.println("tomorrow : " + tomorrow); //선택한 날짜의 하루 다음 날짜
'JAVA' 카테고리의 다른 글
맥북 M1 JAVA 설정 (0) | 2022.03.15 |
---|---|
Ajax로 Spring Controller 에서 패스워드 유효성 검사 방법. (0) | 2019.05.23 |
키워드 Return이 지니닌 2가지 의미 (0) | 2015.07.11 |
값을 반환하는 메소드 (0) | 2015.07.11 |
메소드와 변수의 스코프 (0) | 2015.07.11 |