Date Format in Python | Assignment Expert

Problem Statement:

In the Date Format in Python, we are given seconds as input and we need to convert those seconds to days, hours, minutes, and seconds. We do not need to convert the seconds to date format.

Code for Date Format in Python:

# importing datetime module
import datetime
seconds = float(input("Enter seconds: "))
# converting seconds to days, hours, minutes and seconds
result = datetime.timedelta(seconds = seconds)
result = str(result) # output something like this=> 101451 days, 22:19:49
result = result.split(" ")
days = result[0]
others = result[2].split(":")
hours = others[0]
minutes = others[1]
seconds = others[2]
print("Days: ", days)
print("Hours: ", hours)
print("Minutes: ", minutes)
print("Seconds: ", seconds)


Date Format in Python

Also Read:


Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you