Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get hours:minutes

I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in minutes:seconds

I want to have that in hours:minutes

What changes do I have to make?

This is the peace of script concerned:

if len > 0:
    len = "%d:%02d" % (len / 60, len % 60)
else:
    len = ""

res = [ None ]

I already got the hours by dividing by 3600 instead of 60 but can't get the minutes...

Thanks in advance

Peter

like image 496
Peter Avatar asked Nov 23 '09 18:11

Peter


People also ask

How do you calculate hours and minutes from dates?

To get the hours and minutes from a date, call the getHours() and getMinutes() methods on the date object. The getHours method returns the hours and the getMinutes() method returns the minutes in the specified date.


1 Answers

hours = secs / 3600
minutes = secs / 60 - hours * 60

len = "%d:%02d" % (hours, minutes)

Or, for more recent versions of Python:

hours = secs // 3600
minutes = secs // 60 - hours * 60

len = "%d:%02d" % (hours, minutes)
like image 169
wallyk Avatar answered Sep 23 '22 14:09

wallyk