Hello,
I am working on a small home project and need the very best calculation between a time interval.
Now i have programmed:
dtStartTime = DateTime.Now 'start
'do other things and then....
dtEndTime = DateTime.Now 'endtime
'extracting the seconds and millisecs
sSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Seconds.ToString
sMilliSeconds = (dtEndTime.TimeOfDay - dtStartTime.TimeOfDay).Milliseconds.ToString
'and put it back together
dblSecsAndMsecs = CType((sSeconds + "." + sMilliSeconds), Double)
My question is :
Is there a better way to do this.?.
Ellen
The best calculation between 2 times
Started by Ellen, Jun 22 2012 06:26 AM
4 replies to this topic
#1
Posted 22 June 2012 - 06:26 AM
#2
Posted 22 June 2012 - 06:54 AM
I'm not going to claim that it's "better", but I THINK it is...
Dim dtStartTime As DateTime = DateTime.Now 'Do stuff Dim tsEndTime As TimeSpan = DateTime.Now.Subtract(dtStartTime) Debug.Print(tsEndTime.Seconds & "." & tsEndTime.Milliseconds)
#3
Posted 22 June 2012 - 07:09 AM
Hey
Have you tried the optimised system.diagnostics.stopwatch class Chris posted here:
http://forums.netdui...topwatch-class/
Its in C# but there are online converison tools like the one here:
http://www.developer...t/csharp-to-vb/
Should give you greater resolution than you have now.
Nak.
#4
Posted 22 June 2012 - 12:21 PM
Have you tried using DateTime.Subtract? This returns a TimeSpan object that has both values that can then be used.
Cheers
Brewing Award Winning Beer with a Netduino!
http://diybrewery.com
http://diybrewery.com
#5
Posted 03 July 2012 - 07:31 AM
I'm not going to claim that it's "better", but I THINK it is...
Dim dtStartTime As DateTime = DateTime.Now 'Do stuff Dim tsEndTime As TimeSpan = DateTime.Now.Subtract(dtStartTime) Debug.Print(tsEndTime.Seconds & "." & tsEndTime.Milliseconds)
After a lot of tests, this works indead very well.
Thank you.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users