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);
}
用戶設置時間的數據類型/格式是什麼,並且是與應用程序運行在同一時區的用戶? –