Im creating a date from Calendar with format ("EEE MMM dd kk:mm:ss z yyyy"); example Mon Nov 29 10:10:50 CST 2021. Im then grabbing a date from linked string/data object in format ("MM/dd/yyyy");. In to convert it to the same format as the Calendar date for use to compare the dates. Im not sure why Im getting this errors. Any help would be greatly appreciated
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; import java.time.*; import java.time.format.*; import org.apache.log4j.Level; import org.apache.log4j.Logger; private Date getDateNDaysAgo(int numDays) { log.debug("getDateNDaysAgo 1 " + numDays); Calendar cal = Calendar.getInstance(); Date returnDate = null; cal.add(Calendar.DATE, -(numDays)); returnDate = cal.getTime(); log.debug("getDateNDaysAgo 2" + returnDate); return (returnDate); } if(getDateNDaysAgo != null) { System.out.println("getDateNDaysAgo 2" + getDateNDaysAgo); } Date thresholdDate = null; boolean isAccountCreatedOver25Days = false; String EffectiveHireDateString = link.getAttribute("EffectiveHireDate"); // MM/dd/yyyy if(Util.isNotNullOrEmpty(EffectiveHireDateString)) { DateTimeFormatter mdy = DateTimeFormatter.ofPattern("MM/dd/yyyy"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd kk:mm:ss z yyyy"); try { LocalDate EffectiveHireDate = mdy.parse(EffectiveHireDateString, LocalDate::from); LocalDateTime ldt = LocalDateTime.of(EffectiveHireDate, LocalTime.of(0, 0)); ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault); String formatted = formatter.format(zdt); ZonedDateTime parsedEffectiveHire = formatter.parse(formatted, ZonedDateTime::from); log.debug("parsedEffectiveHire" + parsedEffectiveHire); thresholdDate = getDateNDaysAgo(25); log.debug("thresholdDate" + thresholdDate); if(parsedEffectiveHire != null) { System.out.println("parsedEffectiveHire" + parsedEffectiveHire); } if(parsedEffectiveHire.compareTo(thresholdDate) < 0){ log.debug("parsedEffectiveHire 2" + parsedEffectiveHire); isAccountCreatedOver25Days = true; } } catch (ParseException e) { log.error("Error attempting to parse EffectiveHireDate Date"); } } }