Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java convert an int into hours and minutes

Tags:

java

time

I have two ints 1530 and 830 which is supposed to represent 15:30 and 8:30 in time. What is the best way to convert this number into milliseconds? I was thinking of converting them into strings and sub strings but this seems like a very inefficient approach.

like image 768
Calgar99 Avatar asked Nov 30 '12 23:11

Calgar99


2 Answers

int mins = yourint % 100;
int hours = yourint / 100;  
long timeInMillis = mins * 60000L + hours * 360000L; 
like image 132
Ilya Avatar answered Sep 23 '22 09:09

Ilya


int twentyFourHourTimeToMilliseconds(int time) {
    int hours = time / 100;
    int minutes = time % 100;
    return ((hours * 60) + minutes) * 60000;
}
like image 38
Brigham Avatar answered Sep 23 '22 09:09

Brigham