1

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?

Gocht
  • 9,924
  • 3
  • 42
  • 81

2 Answers2

3

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)
Robᵩ
  • 163,533
  • 20
  • 239
  • 308
1
import time
import re

secs = int(re.sub('\D', '','~153'))
print '%d hours %d minutos %s seconds'%(time.gmtime(secs)[3:6])
Vifonius
  • 43
  • 8