on
자바 30일이 지났는지 체크하는 로직
자바 30일이 지났는지 체크하는 로직
시작일로부터 n일이 지났는지 체크해서 조회기간 체크하는 로직
아래는 10일의 경우 예제
시작일자 기준으로 조회기간 최대 10일 넘을경우 true 반환
public static boolean chkAfterThreeMonth(String fromDate, String toDate) throws ParseException { //fromDate 시작일 toDate 종료일 Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.parseInt(fromDate.substring(0,4))); cal.set(Calendar.MONTH, Integer.parseInt(fromDate.substring(4,6))-1); cal.set(Calendar.DATE, Integer.parseInt(fromDate.substring(6,8))); cal.add(Calendar.DATE, 10); //10일후 SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd"); dateFormatter.format(cal.getTime()); Date fromDateParse = dateFormatter.parse(fromDate); Date toDateParse = dateFormatter.parse(toDate); Date afterTreeMonDate = cal.getTime();//10일후체크 int compare= toDateParse.compareTo(afterTreeMonDate); //시작일자 기준으로 조회기간 최대 10일 넘을경우 true 반환해준다. if(compare>0) { return true; } return false; }
compareTo 를 이용하여 비교할경우 예제
int compare = day1.compareTo(day2); if(compare > 0) { System.out.println("day1>day2"); }else if(compare < 0) { System.out.println("day1
from http://helloworld92.tistory.com/81 by ccl(A) rewrite - 2021-11-08 13:27:29