은은하게 코드 뿌시기

자바 날짜비교 / 날짜계산/날짜수정/기간체크 본문

자바/실무 유용한 것!

자바 날짜비교 / 날짜계산/날짜수정/기간체크

은은하게미친자 2024. 6. 17. 16:54
728x90
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.KOREA);


//01. 날짜 형식 포매터로 선언하기
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
LocalDate currentDate = LocalDate.now();


//02.받아온날짜 포매터로 변환하기 받아온날짜형식은 2024-09-26 17:26:23 포매터와 동일
String date1 = product1.getStr("받아온날짜");
LocalDateTime compareDateTime = LocalDateTime.parse(date1, formatter);


//03. locaDatetime 자바에서 기간체크 하기
Boolean reuslt =  compareDateTime.isBefore(nowdatetime) && compareDateTime.plusMonths(1).isAfter(nowdatetime);
// 오늘보다 이전이고, 설정날짜에 + 한달이 오늘보다 이후인지.

product1.put("newlabel", reuslt);


//04. 날짜 수정하기
scheckdates = nowdatetime.plusWeeks(2).format(formatterM);
scheckdatee = nowdatetime.plusWeeks(2).plusMonths(4).format(formatterM);​

 


string으로 받아서

formatter로 변환해서 localdatetime으로 받아서

 

비교하면됨.

728x90
Comments