Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python time(milli seconds) calculation

Tags:

python

time

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
like image 571
Hulk Avatar asked Dec 15 '09 05:12

Hulk


People also ask

How do you set a millisecond in Python?

Use the timedelta() class from the datetime module to add milliseconds to datetime, e.g. result = dt + timedelta(milliseconds=300) . The timedelta class can be passed a milliseconds argument and adds the specified number of milliseconds to the datetime.

How do I return time in milliseconds?

To get the current time in milliseconds, you just need to convert the output of Sys. time to numeric, and multiply by 1000.

How does Python calculate time interval?

To calculate the total time difference in seconds, use the total_seconds() method on the timedelta object time_diff .


1 Answers

milliseconds = (c.days * 24 * 60 * 60 + c.seconds) * 1000 + c.microseconds / 1000.0
like image 111
John Machin Avatar answered Sep 21 '22 21:09

John Machin