# Thread: So I'm supposed to convert seconds to hours...

1. Member
Join Date
Feb 2011
Posts
11
Rep Power
0

## So I'm supposed to convert seconds to hours...

I went to class yesterday and the teacher says you should be on each lab for about 30 minutes and you should be done, but it takes me at least 4-5 hours to get everything together... I'm doubting whether this is right for me...I like working on this but man I take too much time?

having said that, I'm having problems dividing seconds into hours to get it in the standard time format and the am/pm time format. It looks easy, since you divide 60 by the seconds entered to get hours, divide by 60 again to get the minute then again to get seconds...but it comes out weird?

1. Divide the seconds entered by the user by the number of seconds in an hour
(SECONDS_X_HOUR), the result will be the hours in standard time.
2. Compute the remainder of seconds entered by the user by the number of seconds
in an hour (SECONDS_X_HOUR).
3. Divide the remainder obtained in the previous step by the number of seconds in a
minute (SECONDS_X_MINUTE), the result of this division will be the minutes.
4. The remainder of this last division will be the seconds.
int SECONDS_X_HOUR = 3600;
int SECONDS_X_MINUTE = 60;
int AM_PERIOD = 43199;

System.out.print("Please enter the time in seconds: ");

System.out.println("You must enter a number bigger than 0!");
}
else {

// Standard Format

double standardHour = (Answer / SECONDS_X_HOUR);
double standardMinute = ((standardHour%) /SECONDS_X_MINUTE);
double standardSecond = ((standardMinute%) / SECONDS_X_MINUTE);

System.out.println("Standard Format: " + standardHour + "h., " + standardMinute + "m., " + standardSecond + "s.");
and here's what I've come with, and there is an error on the standardMinute and standardSecond wit the % (Syntax error). at first I just divided the standardHour by seconds_x_minute and standardminute by seconds_x minute but number for hours, minutes and seconds come out the same (figured I pretty much divided the same number for all 3 cases but i'm not too sure). Also I'm not even sure if I'm using the correct data type?

2. Senior Member
Join Date
Aug 2010
Posts
127
Rep Power
0
As far as I know, your only mistake is in the use of the '%'-operator, do you know how that operator works, what it does?

3. Member
Join Date
Feb 2011
Posts
11
Rep Power
0
remainder, supposed to take the remainder of the divided number between the x % y, isn't it? also sometimes the answer comes out to be a loooong decimal, thinking about it now I'm not sure if decimals should happen at all... is that right?

ohohhhh i got it thanks I was on this lab for like 4 hours now and was really frustrated :< confused the definition of remainder with the decimal points you get when you divide with like a calculator or something
Last edited by nope; 02-13-2011 at 10:16 PM.

4. Senior Member
Join Date
Jan 2011
Location
Posts
311
Rep Power
7
So is it working now?

5. Member
Join Date
Feb 2011
Posts
11
Rep Power
0
At least that part, yes, working on figuring out the AM/PM part now.

Got everything but the last part: The supposed answer should have returned without any decimals, but I see .0 after all the hr/min/sec. I haven't learned about math.round nor BigInteger yet and I vaguely remember %2 or something like that (formatter apparently), how do I set it up so no decimals show? "%.2f" is supposed to be with 1 decimal place, isn't it?
Last edited by nope; 02-14-2011 at 12:18 AM.

6. How about declaring your variables as int instead of double, then you don't get the fractional part.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•