?
Solved

Getting hours and minutes from a milisecond value

Posted on 2004-09-11
5
Medium Priority
?
284 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:agrees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12035008
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
 

Author Comment

by:agrees
ID: 12035103
Is there not a ready made utility function?
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 200 total points
ID: 12035296
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 12035446
What you are looking for is in the Calendar class, but you CAN divide yourself, can't you?

;JOOP!
0
 

Author Comment

by:agrees
ID: 12035688
>  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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question