Menu Close

Seconds to Days Hours Minutes

Develop a program that begins by reading a number of seconds from the user. Then your program should display the equivalent amount of time in the form D:HH:MM:SS, where
D, HH, MM, and SS represent days, hours, minutes and seconds respectively.
The hours, minutes and seconds should all be formatted so that they occupy exactly two digits, with a leading 0 displayed if necessary.

sec=int(input("Enter the number of seconds : "))
days=(sec//(24*3600))
hrs=int((sec%(24*3600))/3600)
minutes=int((sec%3600)/60)
seconds=int(sec%60)

print("The Duration is {} days {} hours {} minutes {} seconds".format(days,hrs,minutes,seconds))

Input_1:
          Enter the number of seconds : 563685
Output:
         The Duration is 6 days 12 hours 34 minutes 45 seconds


Input_2:
          Enter the number of seconds : 851005
Output:
         The Duration is 9 days 20 hours 23 minutes 25 seconds


Exec. on linux

Morae!Q!