Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the difference of two DateTime instances in milliseconds

What would be a proper fool-proof way of doing so? I am using ASP.NET MVC 3.

like image 452
sarsnake Avatar asked Jul 23 '12 17:07

sarsnake


People also ask

How do I calculate the time difference between two timestamps?

If you'd like to calculate the difference between the timestamps in seconds, multiply the decimal difference in days by the number of seconds in a day, which equals 24 * 60 * 60 = 86400 , or the product of the number of hours in a day, the number of minutes in an hour, and the number of seconds in a minute.

How does Python calculate time difference in milliseconds?

To get a time difference in seconds, use the timedelta. total_seconds() methods. Multiply the total seconds by 1000 to get the time difference in milliseconds. Divide the seconds by 60 to get the difference in minutes.

Which function returns the time difference in milliseconds?

You can use DiffSeconds() built-in function and multiply the result by 1000. The output will be milliseconds.


2 Answers

        DateTime a = ...
        DateTime b = ...
        var ms = a.Subtract(b).TotalMilliseconds;
like image 52
Jim Bolla Avatar answered Sep 22 '22 15:09

Jim Bolla


(datetime2 - datetime1).TotalMilliseconds
like image 42
mellamokb Avatar answered Sep 19 '22 15:09

mellamokb