Date day1 = set_datetime(2017, Calendar.JUNE, 28, 8, 00, 0);
Date day2 = set_datetime(2017, Calendar.JUNE, 28, 10, 00, 0);
def set_datetime(int year, int month, int day, int hour, int minute, int second) {
Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, minute, second);
Date cal_date = cal.getTime();
return cal_date
}
println "\t\t (day2.getTime() - day1.getTime()) = " + (day2.getTime() - day1.getTime())
(day2.getTime() - day1.getTime()) = 7199996
Milisecond不等於每小時
爲什麼不能7200000毫秒?這裏有點問題。因爲當我從毫秒轉換爲小時時,7199996不是2小時(7200000)
謝謝。但是我必須在早期版本中使用java 6,我們的低端服務器 – ntlam
「或者來自threetenbp或JodaTime的類。」 –