I need express my time in Hours and minutes. This is what I have:
0.0425 hours
~153
seconds, How can I show this as 0 Hours 2 minutos 33 seconds
?
I need express my time in Hours and minutes. This is what I have:
0.0425 hours
~153
seconds, How can I show this as 0 Hours 2 minutos 33 seconds
?
Here is one way.
time = '0.0425 hours'
# Extract time from string
time = time.split()[0]
# Convert time to a number of hours, then a number of seconds
time = float(time)
time = int(time * 3600)
# Compute the constituent elements of the time
hours = time // 3600
minutes = (time // 60) % 60
seconds = time % 60
# Print the result
print '{hours} Hours {minutes} minutos {seconds} seconds'.format(
hours=hours, minutes=minutes, seconds=seconds)
import time
import re
secs = int(re.sub('\D', '','~153'))
print '%d hours %d minutos %s seconds'%(time.gmtime(secs)[3:6])