0

I would like to check if the current time is in a defined frame. I tried the following:

if (LocalTime.now().isBefore(config.getEnd()) && LocalTime.now().isAfter(config.getStart())) {
    ...
}

config.getEnd() and config.getStart() return LocalTimes in the format "HH:mm:ss".

This works as long as the starttime is before the endtime. But if this program should execute in the middle of the night between 23:00:00 and 02:00:00 then of course it doesn't. With the old java.util.date I would deduct 1 day from the starttime but I have no days here.

Does anyone know an elegant solution to this?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Moh-Aw
  • 2,976
  • 2
  • 30
  • 44

0 Answers0