5
我有一个应用程序,它从用户获取开始和结束时间,并在(开始时间)运行到(结束时间)时启动特定进程,因为示例我使用TimerTask实用程序,以防从该用户启动进程高达(结束时间),我不能设置开始时间我如何comapare用户时间的当前时间和运行(开始时间)和系统时间在Java如何在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);
}
用户设置时间的数据类型/格式是什么,并且是与应用程序运行在同一时区的用户? –