計算時間的時候碰到的問題:
Date d = new Date(); long currtime = d.getTime(); //獲取當前時間 long starttime = currtime - 30* 86400000; //當前時間減掉一個月的毫秒數搜索 System.out.println(currtime + "------"+starttime);
得到的結果竟然是currtime 要小於starttime,為什么會越減越大呢?
//因為30* 86400000 超出int的取值范圍了, long a= (long)30*(long)86400000;
總結:在進行long型數據計算的時候需要在數據前加上(long),否則默認為int類型計算,而一旦超出int取值范圍那么就會出現上述問題。應避免上述問題。