+5

# How to convert seconds to minutes, hours, and days?

1/24/2017 11:23:06 PM

Kyle Martin

31 Answers

New Answer

+17

Not for the accurate result. If you want to split the seconds into the above you can use this: int sec = 3700, mins, hours, days; sec -= (60 * 60 * 24) * (hours = sec / (60 * 60 * 24)); sec -= (60 * 60) * (days = sec / (60 * 60)); sec -= 60 * (mins = sec / 60);

+6

unsigned int d=sec/86400; sec=sec%86400; unsigned int h=sec/3600; sec=sec%3600; unsigned int m=sec/60; sec=sec%60;

+5

It would be 1 hour 1 minute and 40 seconds (cmon, basic math xD), but whatever. You know I gave you the complete code for this 10 comments ago? Well, here it is again: int input, sec, mins, hours, days; cout << "Enter a number:" << endl; cin >> input; sec = input; sec -= (60 * 60 * 24) * (hours = sec / (60 * 60 * 24)); sec -= (60 * 60) * (days = sec / (60 * 60)); sec -= 60 * (mins = sec / 60); cout << input << " seconds are " << days << " day(s) " << hours << " hour(s) " << mins << " minute(s) and " << sec << " second(s)" << endl; And don't say you ONLY want hours if clearly you also want it to display minutes seconds and days at the same time^^

+1

https://code.sololearn.com/ct0zZ5GRO138/?ref=app d=secArg/(3600*24); h=(secArg%(24*3600))/3600; m=(secArg%3600)/60; s=(secArg%3600)%60; @Robobrime, i understand Your point of view but i use one operation less excliding assignings and not needed multiplications ofcourse.

+1

int hours = seconds / 3600; int minutes = ((seconds % 3600) / 60); int days = seconds/86400; this will calculate minutes, hours and days from the given seconds...

+1

to convert seconds to minutes ÷ seconds by 60, minutez to hours ÷ minutes by 60, hours to days divide hours by 24! SIMPLE

+1

You still didn't answer what the exact output for 3700 seconds should look like. Apparently you don't want it to be 1 hour (rounded) and you also don't want it to be 1.0278 hours (exact, but decimals), so what do you want? 37/36 hours? 10278e-4 hours?

0

Do must work evreday?

0

idk but nice question

0

In c++ Int main( ) { Int s,d,h,m,s1; Cout‹‹"enter time in seconds"; Cin››s; d=s/86400; /*here 1 day= 86400 seconds. So it is the formula of finding days from hours*/ S=s%86400 ;/*% stands for modulus or mod*/ H=s/3600; S=s%3600; M=s/60; S2=s%60; Cout‹‹d‹‹"days "‹‹h‹‹"hours "‹‹m‹‹" minutes "‹‹s‹‹" seconds "; Return 0; } This is also known as denomination programme

0

Minutes = Seconds * 60 Hours = Minutes * 60 Hours = Seconds * 60 * 60 Hours = Seconds * 3600 Days = Hours * 24 Days = Seconds * 3600 * 24 Days = Seconds * 86400

0

"65days 1hour 37minutes 67 seconds"? @Kyle 🤣... 67 seconds

0

problem solved thank u

0

So, problem solved now or any questions left?

0

I mean pseudocode....sorry I've been doing hw all day..

0

I've only have done c++

0

my bad I'm still getting used to c++

0

like 65 days 1 hour 37 minutes 67 seconds

0

I know. I'm trying to get it using a math equation

0

You can't just only display the hours and then not round the result or have some decimals, that's not how it works...