String businessDate = null;
String CUTOVER_TIME = "22:30";
Date dateOfReport = new Date();
Date businessDateyyyymmdd = null;
SimpleDateFormat dateOnly = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyyMMdd hh:mm");
businessDate = dateOnly.format(dateOfReport);
businessDate = dateOnly.format(dateOfReport);
Date cutoverTime = sdfDateTime.parse(businessDate + CUTOVER_TIME);
businessDateyyyymmdd = dateOnly.parse(businessDate);
if (cutoverTime.after(dateOfReport)) {
Calendar c = Calendar.getInstance();
c.setTime(businessDateyyyymmdd);
c.add(Calendar.DATE, -1);
businessDateyyyymmdd = c.getTime();
businessDate = dateOnly.format(businessDateyyyymmdd);
} else {
if (cutoverTime.before(dateOfReport)) {
System.out.println("no cutover");
}
}
Error appeared as Exception in thread "main" java.text.ParseException: Unparseable date: "2022071822:30" at java.base/java.text.DateFormat.parse(DateFormat.java:395) at com.anz.test.Employee.main(Employee.java:81)
hhmeans 12-hour hour-of-day. I think you meanHH. I'd also strongly recommend abandoning java.util.Date and moving to the java.time classes. - Jon Skeet"2022071822:30"and the format"yyyyMMdd hh:mm". See the difference? One would be that you'd need to useHH:mm, the other would be that your format requires a space between date and time and your passed in timestamp doesn't seem to have any. - ThomasDate,SimpleDateFormatandCalendarsince they are so troublesome. Their modern replacement is java.time, which I recommend using instead. It's so much nicer to work with and also lends itself much better to your particular logic. - Ole V.V.hh? That's what's failing to parse 22:30, which is what you asked about. If you want to know something different, you should ask a different question. Also note that in the code you've posted, you don't have a space between the date and the time, but there is one in the pattern. Finally, again, I would advise you not to use these classes. - Jon Skeet