0

I have the code below that prints a text every day. However I would like it to print the text only on -- for example -- 8 o'clock in the morning.

String text = "Test"; 
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {         
    public void run() {             
        System.out.println(text);
    }       
}, 0, 1000 * 60 * 60);

In my code, the print time depends on the time I run the code and the code of course does not consider the daylight saving time changes etc.

Aneesh R S
  • 3,807
  • 4
  • 23
  • 35
  • You could check the current time use the Date class. For more information, check https://docs.oracle.com/javase/8/docs/api/java/util/Date.html – Pablo Apr 24 '18 at 19:58
  • 3
    Possible duplicate of [How to run certain task every day at a particular time using ScheduledExecutorService?](https://stackoverflow.com/questions/20387881/how-to-run-certain-task-every-day-at-a-particular-time-using-scheduledexecutorse) – Jacob G. Apr 24 '18 at 20:01

1 Answers1

0

Use public void schedule(TimerTask task, Date time) of Timer