Reply EDIT based on comments
This answer only tries to calculate the total number of elapsed milliseconds between two points where the time is obtained directly from DateTime.Now . As for the conversation, he realized that DateTime.Now is vulnerable to external influences. Therefore, the best solution would be to use the Stopwatch class. Here's a link that better explains (IMO) and discusses performance between DateTimeNow, DateTime.Ticks, StopWatch .
Original answer
The question is how do you convert it to int. You need better casting and additional elements :) It may look simple compared to an effective timer. But it works:
DateTime startTime, endTime; startTime = DateTime.Now; //do your work endTime = DateTime.Now; Double elapsedMillisecs = ((TimeSpan)(endTime - startTime)).TotalMilliseconds;
There is a link on the Internet that you can also check.
source share