C++ || Convert Time From Seconds Into Hours, Min, Sec Format

DisplayHrsMinSec

Here is another simple programming assignment. This page will demonstrate how to convert time from -seconds- into HH::MM::SS (hours, minutes seconds) format. So for example, if you had an input time of 9630 seconds, the program would display the converted time of 2 hours, 40 minutes, and 30 seconds.

Using simple math, this program utilizes the modulus operator, and the division operator during the conversion process.

REQUIRED KNOWLEDGE FOR THIS PROGRAM

Modulus - What is it?
How Many Seconds Are In One Hour?
How Many Seconds Are In One Minute?


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output
(Note: the code was compile five separate times to display different output)

====== RUN 1 ======

Enter a time in seconds: 9630

The time in HH:MM:SS format is: 2 hours, 40 minutes, and 30 seconds!

====== RUN 2 ======

Enter a time in seconds: 7200

The time in HH:MM:SS format is: 2 hours, 0 minutes, and 0 seconds!

====== RUN 3 ======

Enter a time in seconds: 45

The time in HH:MM:SS format is: 0 hours, 0 minutes, and 45 seconds!

====== RUN 4 ======

Enter a time in seconds: 134

The time in HH:MM:SS format is: 0 hours, 2 minutes, and 14 seconds!

====== RUN 5 ======

Enter a time in seconds: 31536000

The time in HH:MM:SS format is: 8760 hours, 0 minutes, and 0 seconds!

Leave a Reply