Java - System.currentTimeMillis(); Not Returning Difference

后端 未结 3 1285
长发绾君心
长发绾君心 2021-01-20 17:02

For some reason I am getting a consistent 3600 returned by the function:

private static long getCountdownLeft() {
    long now = System.currentTimeMillis();
         


        
3条回答
  •  迷失自我
    2021-01-20 17:52

    Your code will consume little time before invoke getCountdownLeft. try update this code :

        public static void Main(String[] args) throws InterruptedException {
        long gameTime = System.currentTimeMillis(); // pass the current time
        Thread.currentThread().sleep(1000); // sleep one second before invoke getCountdownLeft
        System.out.println("Time is " + getCountdownLeft(gameTime));
    }
    

提交回复
热议问题