Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Difference between 2 times into Milliseconds?

I have two masked TextBox controls and was wondering how I'd go about getting the time in each one and then converting the difference into milliseconds. Like, say in tb1 I write "12:01" and in tb2 I write "12:02", and then click a button. Once the button's clicked it starts a timer and at 12:02 a messagebox will be displayed. I know how to do all of it except for the time conversion part.

How can it be achieved?

like image 864
jay_t55 Avatar asked Sep 28 '09 13:09

jay_t55


People also ask

How do you find the difference between two times with milliseconds?

Using the general formula =B2-A2 will get an error result while the value in B2 is smaller than A2, here I introduce a formula to handle this.

How do I calculate time difference between milliseconds in Excel?

There is also an elegant alternative to this solution: You can simply multiply the time value by 86400000 to convert it into milliseconds. This works because of the internal numeric format used by Excel where 1 is equal to 24h = 24h × 60min/h × 60s/min × 1000ms/s = 86400000ms.

How do you find the 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 do you calculate time in milliseconds?

To convert a second measurement to a millisecond measurement, multiply the time by the conversion ratio. The time in milliseconds is equal to the seconds multiplied by 1,000.


1 Answers

DateTime dt1 = DateTime.Parse(maskedTextBox1.Text); DateTime dt2 = DateTime.Parse(maskedTextBox2.Text); TimeSpan span = dt2 - dt1; int ms = (int)span.TotalMilliseconds; 
like image 111
MusiGenesis Avatar answered Oct 05 '22 17:10

MusiGenesis