12

How to calculate milliseconds,from the code below.

a = datetime.datetime.now() b = datetime.datetime.now() c = b - a >>> c >>> c.days 0 >>> c.seconds 4 >>> c.microseconds 
1

2 Answers 2

15
milliseconds = (c.days * 24 * 60 * 60 + c.seconds) * 1000 + c.microseconds / 1000.0 
Sign up to request clarification or add additional context in comments.

1 Comment

This answer is wrong!if time delta is 1 minute exactly,result will be 0,not our expect!
14

Or, new since 2.7:

c.total_seconds()*1000 

(https://docs.python.org/2/library/datetime.html)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.