public class App {
public static void main(String[] args) {
TimerTask repeatedTask = new TimerTask() {
public void run() {
// Code to execute
}
};
Timer timer = new Timer("Timer");
Date first = new Date();
long period = 1000L * 60L * 60L * 24L;
timer.scheduleAtFixedRate(repeatedTask, first, period);
}
}
I am trying to make my code repeat itself every day at 9PM. The problem is that for the first occurrence I'm trying to set the date to today at 9PM, but every method to set the time in a Date object is deprecated. The only other way I have found is to use a Calendar, but the method scheduleAtFixedRate only takes a Date or a Long.