Python - time difference in milliseconds not working for me

Solution 1:

Try using total_seconds method:

print time_diff_wind.total_seconds() * 1000

That method is equivalent to: (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6

Note: It's available since version 2.7

Solution 2:

>>> a = datetime.datetime.now()
>>> b = datetime.datetime.now()
>>> a
datetime.datetime(2013, 8, 25, 2, 5, 1, 879000)
>>> b
datetime.datetime(2013, 8, 25, 2, 5, 8, 984000)
>>> a - b
datetime.timedelta(-1, 86392, 895000)
>>> b - a
datetime.timedelta(0, 7, 105000)
>>> (b - a).microseconds
105000
>>> (b - a).seconds
7
>>> (b - a).microseconds / 1000
105

your microseconds don't include the seconds that have passed