Reputation: 1555
i have one application which get the start and end time from the user and start the particular process at (start time) runs upto the (end time),for sample i use TimerTask utility in case it only start the process from the current time and runs upto (end time) i cant set the start time how do i comapare the user time(start time) and system time in java
//my sample program
import java.sql.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Main {
public static void main(String[] argv) throws Exception {
int numberOfMillisecondsInTheFuture=1000;
// start time= dynamically set by user
// end time =dynamically set by user
Date timeToRun = new Date(System.currentTimeMillis() + numberOfMillisecondsInTheFuture);//here is the problem.
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
//System.out.println("doing");
//doing some task not related to this question
}
}, timeToRun);
}
Upvotes: 4
Views: 5924
Reputation: 2951
if this helps How i can run my TimerTask everyday 2 PM You may have to do some changes to fit to your use.
Upvotes: 3