2012-11-30 12 views
7

Ho due inte 1530 e 830 che dovrebbe rappresentare 15:30 e 8:30 in tempo. Qual è il modo migliore per convertire questo numero in millisecondi? Stavo pensando di convertirli in stringhe e sottostringhe ma questo sembra un approccio molto inefficiente.Java converte un int in ore e minuti

risposta

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

Grazie per la risposta rapida, stavo andando su tutto sbagliato – Calgar99

+0

manca uno zero! – 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

O vedere java.util.concurrent.TimeUnit

Problemi correlati