Convert time unit Seconds in Days, Hours, Minutes
Develop a python 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.
## #Python's program to convert number of seconds to days, hours, minutes and seconds. ## #Define the constants SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 #Read the inputs from user seconds = int(input("Enter number of seconds: ")) #Calculate the days, hours, minutes and seconds days = seconds / SECONDS_PER_DAY seconds = seconds % SECONDS_PER_DAY hours = seconds / SECONDS_PER_HOUR seconds = seconds % SECONDS_PER_HOUR minutes = seconds / SECONDS_PER_MINUTE seconds = seconds % SECONDS_PER_MINUTE #Display the result print("The duration is: ","%d:%02d:%02d:%02d"%(days,hours,minutes,seconds))
Sample output of above program.
C:\Python\programs>python program.py
Enter number of seconds: 9547863
The duration is: 110:12:11:03
C:\Python\programs>
Enter number of seconds: 9547863
The duration is: 110:12:11:03
C:\Python\programs>
2017-11-25T22:38:01+05:30
2017-11-25T22:38:01+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution