How to calculate time interval between two time strings in Python

0 votes
Need to find the difference between the two times, how do I do this?

Do I use the date/time module?

My goal is to calculate the averages of multiple time duration. I am thinking for storing them in a list and later need to calculate the average. For the averaging, should I convert to seconds and then average?
Nov 29, 2018 in Python by Anirudh
• 2,070 points

edited Dec 11, 2018 by Anirudh 133 views

1 answer to this question.

0 votes

Try doing this - It is efficient for timing short-term events.

import time
start = time.time()

time.sleep(10)  # or anything

done = time.time()
elapsed = done - start
print(elapsed)
answered Nov 29, 2018 by Nymeria
• 3,520 points

edited Dec 11, 2018 by Nymeria

Related Questions In Python

0 votes
1 answer

how to compare two strings in python?

compare two string in python >>> s1="abc ...READ MORE

answered Mar 25 in Python by rajesh
• 1,210 points
41 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
186 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
63 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
44 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 232 views
+4 votes
6 answers
0 votes
1 answer

How to parse date/time string with timezone abbreviated name in Python?

The parse() function in dateutil can't handle ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,520 points
177 views
0 votes
1 answer

How to activate virtualenv in Python? Help!

One major issue I see is that ...READ MORE

answered Nov 5, 2018 in Python by Nymeria
• 3,520 points

edited Dec 17, 2018 by Nymeria 207 views