How do I convert seconds to hours, minutes and seconds?

前端 未结 12 2284
执笔经年
执笔经年 2020-11-22 11:00

I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds.

Is there an easy way to convert the seconds to

12条回答
  •  情深已故
    2020-11-22 11:26

    The following set worked for me.

    def sec_to_hours(seconds):
        a=str(seconds//3600)
        b=str((seconds%3600)//60)
        c=str((seconds%3600)%60)
        d=["{} hours {} mins {} seconds".format(a, b, c)]
        return d
    
    
    print(sec_to_hours(10000))
    # ['2 hours 46 mins 40 seconds']
    
    print(sec_to_hours(60*60*24+105))
    # ['24 hours 1 mins 45 seconds']
    

提交回复
热议问题