Concatenate time Django

2

I have a project in django where I have the fields hour, minutes, seconds separately I need to concatenate them so that they remain in the format "% H:% M:% S"

direferencia=6243.0 #Este valor esta en segundos

hora=math.floor(diferencia/3600) #devuelve 1.0

minuto=math.floor((diferencia - (hora * 3600)) / 60) #devuelve 44.0

segundo=math.floor(diferencia - (hora * 3600 + minuto * 60))#devuelve 3.0
    
asked by jhon1946 13.08.2016 в 04:55
source

1 answer

3

It's simpler than what you're doing, use the module time

>>> import time
>>> time.strftime('%H:%M:%S', time.gmtime(6243.0))
    '01:44:03'
>>>

This is what I was referring to in the comment

>>> import datetime
>>> str(datetime.timedelta(seconds=86400))
'1 day, 0:00:00'
>>> str(datetime.timedelta(seconds=86401))
'1 day, 0:00:01'
>>> str(datetime.timedelta(seconds=86400))
'1 day, 0:00:00'
>>> str(datetime.timedelta(seconds=86399))
'23:59:59'
    
answered by 13.08.2016 / 07:20
source