出于某种原因,我得到了函数返回的一致 3600:
private static long getCountdownLeft() {
long now = System.currentTimeMillis();
long elapsedMillis = now - initialTime; //difference of current 'current' time
long millisLeft = secondsOfGame * 1000 - elapsedMillis;
return millisLeft/1000;
}
public static void Main(String[] args ) {
System.out.println("Time is " + getCountdownLeft());
}
private static int secondsOfGame = 3600;
private static long initialTime = System.currentTimeMillis();
这是事件驱动的。我希望每次调用该函数时都能看到时间上的差异。我只是使用 main 来表明我正在调用它。