Asked • 07/09/19

Split down a number in seconds to days, hours, minutes, and seconds?

I've heard that it's possible to accomplish this using the modulus `%` operator present in most programming languages. The real question is, how? I'm unfamiliar with how modulus works, so I've had difficulties using it in the past. Given the present time here in seconds since 1970, `1307758473.484`, how can I calculate how many years that is, days that is, hours that is, and minutes that is using modulus? I'm essentially looking to format it like this: "5 years, 10 days, 12 hours, 7 minutes, and 18.56 seconds". How would I do this? I'm really interested in learning the logic behind this and _not_ interested in a simple drop-in solution.

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.