4

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);
  }
Mr.Cool
  • 1,525
  • 10
  • 32
  • 51
  • What is the data type/format the user sets the time with and is the user in the same time zone as the application runs in? – Kai Huppmann Jun 01 '12 at 11:45

1 Answers1

3

if this helps How i can run my TimerTask everyday 2 PM You may have to do some changes to fit to your use.

Community
  • 1
  • 1
BOSS
  • 2,931
  • 8
  • 28
  • 53