Results 1 to 4 of 4
- 04-05-2010, 11:58 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 36
- Rep Power
- 0
a constructor to convert seconds to hours, min & seconds
hey everyone,
I am trying to figure out how to make the following: converting a value of seconds and convert it to the amount of hours,minutes and seconds it is.
For instance 7200 sec would give me 2 hours, 0 minutes and 0 seconds.
I know it is something with % but I can't figure out how to do it.
The code I started out with looks like this:
public Time(int totSeconds){
something like ==> int out = totSeconds % 3600; this gives me the rest but not the amount of hours :s
...
if anyone can help me, thanks in advance :)
- 04-05-2010, 12:39 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,412
- Blog Entries
- 7
- Rep Power
- 17
This is simpler than math 101: there are 3600 seconds in an hour, you have 7200 seconds, so you have 7200/3600 == 2 hours.
kind regards,
Jos
- 04-05-2010, 12:56 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 36
- Rep Power
- 0
but how does it work with minutes and seonds? for example 7350 seconds?
if you devide then there is a rest somewhere but where?
- 04-05-2010, 01:08 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,412
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
JoptionPane.showmessegeDialog that close after 20 seconds
By itaipee in forum AWT / SwingReplies: 1Last Post: 02-01-2010, 01:47 PM -
Convert microseconds to seconds
By Basit56 in forum New To JavaReplies: 4Last Post: 12-31-2009, 05:54 AM -
Difference in seconds between two times
By jazzy639 in forum New To JavaReplies: 11Last Post: 09-26-2009, 06:58 PM -
getting time elapsed in seconds
By ali_sakar in forum New To JavaReplies: 3Last Post: 03-06-2009, 08:37 AM -
Need help with calculate the number of seconds
By ProUnbeatable in forum New To JavaReplies: 5Last Post: 10-11-2008, 03:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks