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
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.
To get the current time in milliseconds, you just need to convert the output of Sys. time to numeric, and multiply by 1000.
To calculate the total time difference in seconds, use the total_seconds() method on the timedelta object time_diff .
milliseconds = (c.days * 24 * 60 * 60 + c.seconds) * 1000 + c.microseconds / 1000.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With