我想做一個簡單的時間計算,我在文本框中顯示經過的時間。問題是我的方法在返回其他東西時返回值爲零。爲了這個目的,多長時間可以投入整數?任何幫助表示讚賞。爲什麼時間計算不正確?
我的代碼:
total_hours_paycycle是一個長期擁有的259200000.值是表示這樣的調試器
try{
int total_minutes = (int) ((total_hours_paycycle/ (1000*60)) % 60); //<--Should return non-zero value, but is returning 0
int total_hours = (int) ((total_hours_paycycle/ (1000*60*60)) % 24); //<--Should return non-zero value, but is returning 0
hours_worked_converted = total_hours + "." + total_minutes; //<--returning 0.0
total_for_paycycle.setText("Total: "+hours_worked_converted + " hrs.");
}catch(Exception e){
total_for_paycycle.setText("Total: - ");
}
你爲什麼想到第一次計算返回12? (25920000000/60000)%60 = 0. – Joel
當total_hours_paycycle = 4320000時,它返回1小時12分鐘。我不明白爲什麼25920000000返回零。 – DollaBill