Ynns

String 타입 날짜 Date 타입 비교 본문

JAVA

String 타입 날짜 Date 타입 비교

yunassnn 2020. 1. 20. 18:58

DateTimeFomatter 사용해서 날짜 형식 잡기

> LocalDateTime.now() 현재 시간 잡기

> isBefore 사용해서 비교

 

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime currentDay = LocalDateTime.now();

 //각 매장의 마감여부 관계없는 배송일 날짜/배송시간/회차 조회
Map<String,Object> mapDeliveryday = batchOrderMapper.getDeliverydayMatch(paramMap);
if (mapDeliveryday != null) {
	...
    nearClosingday  = mapDeliveryday.get("closingday")  == null ? nearClosingday  : (String) mapDeliveryday.get("closingday");
	...	
    LocalDateTime closingDate = LocalDateTime.parse(nearClosingday, formatter);
	if(!currentDay.isBefore(closingDate)){
		throw new AlertException("주문이 마감된 매장이 있습니다, 확인 후 다시 첨부해주세요.");
	}
}

 

Comments