tag:blogger.com,1999:blog-8980734269859237005.post1822445438682815894..comments2024-01-30T01:03:21.768-08:00Comments on DevCurry: Calculate the Seconds, Milliseconds and Microseconds using C# and VB.NETSuprotim Agarwalhttp://www.blogger.com/profile/08349831623922214390noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8980734269859237005.post-60769912263423117742009-08-31T00:52:11.008-07:002009-08-31T00:52:11.008-07:00Thanks Kevin, Erik and Markus. That was quite info...Thanks Kevin, Erik and Markus. That was quite informative. The updates have been made to the original post for the benefit of future users and webdevs like me!Suprotim Agarwalhttps://www.blogger.com/profile/08349831623922214390noreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-61987890943577342312009-08-30T12:06:43.822-07:002009-08-30T12:06:43.822-07:00First; I totally agree with Kevin that this is a m...First; I totally agree with Kevin that this is a messy way of calculating the elapsed time between two DateTimes.<br /><br />And second. Eric hinted that using DateTime.Now for timing sure is bad. Although the limitation does not lie within the TimeSpan struct, but with the underlying implementation of DateTime.Now. For timing you should use the Stopwatch class in System.Diagnostics. See <a href=Markus Olssonhttps://www.blogger.com/profile/04294756312801923101noreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-12975852804820693962009-08-29T18:58:50.703-07:002009-08-29T18:58:50.703-07:00The problem with this is that TimeSpan only has a ...The problem with this is that TimeSpan only has a resolution of 100ms on an NT4 or better system - which means you can't rely on it being accurate for anything less than that amount, give or take. If you really need accurate timing at those levels, you need the high performance timer APIs or multimedia timer APIs.Erikhttps://www.blogger.com/profile/00113019952074669440noreply@blogger.comtag:blogger.com,1999:blog-8980734269859237005.post-16656398500019660742009-08-29T10:30:08.093-07:002009-08-29T10:30:08.093-07:00The DateTime type implements an operator for subtr...The DateTime type implements an operator for subtraction that returns a TimeSpan object. This would be my suggestion:<br /><br />//-----------<br />DateTime start = DateTime.Now;<br />Thread.Sleep(10);<br />DateTime end = DateTime.Now;<br />TimeSpan span = end - start;<br /> Console.WriteLine("Ticks: " + span.Ticks);<br />//-----------<br /><br />From there, you can access Kevinnoreply@blogger.com