Yesterday I was developing a XML reader where the app will wait for a certain period of time (in minutes) before re-processing the same xml files again. To get elapsed time in minutes, I used the TimeSpan class which represents the time interval together with DateTime object. By setting the Start time and using the Now.Subtract method to subtract the start time and the current time, you can obtain a result of type TimeSpan. Here is a brief sample source code of what I have.
'Declare variables
Private tsElapseTime As TimeSpan
Private dtStartTime As DateTime
'Call to start counting
Private Sub StartTime() As Integer
dtStartTime = Now
End Sub
'Call to get the elapsed time in minutes
Private Function GetTimeSpanInMins() As Integer
tsElapseTime = Now.Subtract(dtStartTime)
return tsElapseTime.Minutes
End Function
For More Coding Tips and Tricks, subscribe now.
0 comments:
Post a Comment