Getting hours and minutes from a milisecond value

Hi all, very easy question!

I have a millisecond value which indicates the time left a program has to run.  How do I convert this into a String of the format:  hours/mins/seconds
agreesAsked:
Who is Participating?
 
brettmjohnsonConnect With a Mentor Commented:
None that I know of.  The math is pretty trivial.  
It is unlikely that there is a standard library function for  an infrequently used,
yet trivial to calculate transformation.
0
 
brettmjohnsonCommented:
There are 1000 milliseconds in a second, 60 seconds in a minute, 60 minutes in an hour.

static final long MSecsPerHour =  60*60*1000L;
static final long MSecsPerMin = 60*1000L;
static final long MSecsPerSec = 1000L;

long msecs;
int hours, minutes, seconds;

hours = msecs/MSecsPerHour;
msecs %= MSecsPerHour;
minutes = msecs/MSecsPerMin;
msecs %= MSecsPerMin;
seconds =  msecs/MSecsPerSec;







0
 
agreesAuthor Commented:
Is there not a ready made utility function?
0
 
sciuriwareCommented:
What you are looking for is in the Calendar class, but you CAN divide yourself, can't you?

;JOOP!
0
 
agreesAuthor Commented:
>  What you are looking for is in the Calendar class, but you CAN divide yourself, can't you?

There are plenty of existing Java library functions which I could write myself.  But if it exists already then there are many reasons to use the existing function and NOT write your own.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.