JAVA/java

Java 날짜 유효성(포멧) 체크

JJunDol2 2020. 7. 14. 15:38
public static boolean dateCheck(String checkDate) {
  SimpleDateFormat dateFormatParser = new SimpleDateFormat("yyyyMMdd", Locale.KOREA);

  dateFormatParser.setLenient(false);
  try {
      dateFormatParser.parse(checkDate);
      return true;
  } catch (ParseException e) {
      return false;
  }
}

- checkDate가 yyyyMMdd 포멧에 부합하는지 체크

- dateFormatParser.setLenient(false); : false이면 엄격한 체크

- checkDate가 yyyyMMdd에 맞으면 true, 아니면 예외발생

 

- 해당 내용을 파일 파싱 배치에 추가하여 파싱할 파일에서 날짜값이 유효한 값인지 확인하기 위해 사용함