2012-11-30 45 views
7

我有兩個整數1530和830,它們應該表示15:30和8:30時間。將此數字轉換爲毫秒的最佳方法是什麼?我正在考慮將它們轉換爲字符串和子字符串,但這似乎是一種非常低效的方法。Java將int整數轉換爲小時和分鐘

回答

7
int mins = yourint % 100; 
int hours = yourint/100; 
long timeInMillis = mins * 60000L + hours * 360000L; 
+0

謝謝你的快速反應,我會約完全錯誤 – Calgar99

+0

缺少一個零! – irreputable

7
int twentyFourHourTimeToMilliseconds(int time) { 
    int hours = time/100; 
    int minutes = time % 100; 
    return ((hours * 60) + minutes) * 60000; 
} 
2
(x/100) * 3600000L + (x % 100) * 60000L 
0

還是看java.util.concurrent.TimeUnit中

相關問題