I have the following python code to calculate how many days, hours, minutes, seconds and milliseconds an amount of marsdays is. I want the output to be:
x sols = x days, x hours, x minutes, x seconds, x milliseconds
I found out I had to use timedelta because it uses milliseconds, which I need.
I have written the following code but it doesn't give a correct output for the values. When they're >60 they need to be passed on because 60 seconds equals 1 hour. But the values can go >60. for example, when I enter a value >1, like 4, I get the aswer: 4 sol = 4 days, 2 hours, 38 minutes, 7220 seconds, 976 milliseconds.
from datetime import datetime, timedelta
sol = timedelta(hours=24,minutes=39,seconds=35,milliseconds=244)
amount = input("Amount of sols: ")
earth=int(amount)*sol
hours = int(earth.seconds/3600)
minutes = int((earth.seconds-(hours*3600))/60)
secondes = int(earth.seconds-(minutes*60))
millisecondes = int(earth.microseconds/1000)
print (amount + " sol = " + str(earth.days) + ' days, ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, ' + str(secondes) + ' secondes, ' + str(millisecondes) + ' millisecondes')
The hours, minutes and milliseconds are calculated this way because timedelta can't give them apparently.
earth.days
earth.seconds
exist, but
earth.hours
earth.minutes
earth.milliseconds
don't exist. which I don't understand because I can give them values as seen on line 2.
I think the way I try to achieve what i want isn't correct.
divmodmight be useful to you. - leewzsecondes. I bet that yoursecondesis off by a multiple of 3600. - leewzsecondes. - leewz