It is necessary to do so that if a certain time comes, then the screen displays what another doctor is taking. Is it possible to write somehow using the example below?

if (i > 16:00) { принимает другой врач к примеру } 

Closed due to the fact that the essence of the question is not clear to the participants fori1ton , Qwertiy , Barmaley , AK , Alexey Shimansky 10 Jan '17 at 15:39 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    This is done quite simply:

     LocalTime changeTime = LocalTime.of(16, 0); if (LocalTime.now().isBefore(changeTime)) System.out.println("принимает первый врач"); else System.out.println("принимает второй врач"); 

    If you want to do this asynchronously, you can start the timer:

     LocalTime changeTime = LocalTime.of(16, 0); LocalTime now = LocalTime.now(); long delay; if (now.isAfter(changeTime)) delay = changeTime.getLong(ChronoField.MILLI_OF_DAY) - now.getLong(ChronoField.MILLI_OF_DAY) + TimeUnit.DAYS.toMillis(1); else delay = changeTime.getLong(ChronoField.MILLI_OF_DAY) - now.getLong(ChronoField.MILLI_OF_DAY); new Timer().scheduleAtFixedRate( new TimerTask() { @Override public void run() { System.out.println("принимает второй врач"); } }, delay, TimeUnit.DAYS.toMillis(1)); 

    It will display the line once a day, at 16:00

      For this it is better to use the Quartz library. It is not very simple, but very flexible. An example can be searched here .

      Or look in the direction of Spring sheduler . It is worth paying attention to the cron parameter, the syntax is similar to Quart, more details can be found here .

      In your case, the crown should get some such "0 0 16 * * *"