Rob
Rob

Reputation: 181

Calculating the times into minutes

I am working on my python code as I want to calulcating on the program time to convert it into minutes. When the program start at 12:00AM and my current time show as 1:00AM. The end time show for the program is 6:00AM, so I want to work out between 1:00AM and 6:00AM to take it away then multiply it by 60 to convert it into minutes.

Example: 6 take away 1 which is 5 then I want to multply it by 60 which it is 300 minutes.

Here is the code:

current_time = int(time.strftime("%M"))
prog_width = self.getControl(int(program_id)).getWidth()
prog_length = int(prog_width) / 11.4 - current_time
prog_length = str(prog_length)
prog_length = prog_length.replace('.0', '')
prog_length = int(prog_length)
print prog_length

Can you please show me an example of how I can calculating between 1:00AM and 6:00AM to take it away then convert it into minutes when multply by 60?

Upvotes: 0

Views: 58

Answers (1)

user2201041
user2201041

Reputation:

You can use the datetime module

from datetime import timedelta

start = timedelta(hours=1)
end = timedelta(hours=6)
duration = end - start
print duration.total_seconds() / 60

Upvotes: 1

Related Questions