I am building an Interval Timer and it is working fine except that where I am displaying the seconds counting down it always skips the first second. For instance, when counting down from 10 it displays ...08...07... and doesn't change to 09 first as I am expecting.
I have been going in circles trying to flush this out and am at a loss. Any insight into why it is behaving this way would be appreciated.
intervalTime is a Date
remainingTime is a TimeSpan
tMain timer is set to tick every second
I have been going in circles trying to flush this out and am at a loss. Any insight into why it is behaving this way would be appreciated.
intervalTime is a Date
remainingTime is a TimeSpan
tMain timer is set to tick every second
VB.NET:
intervalHours = 0
intervalMinutes = 0
intervalSeconds = 10
intervalTime = Date.Now.AddHours(intervalHours).AddMinutes(intervalMinutes).AddSeconds(intervalSeconds)
tMain.Start()
VB.NET:
Private Sub tMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tMain.Tick
remainingTime = intervalTime.Subtract(Date.Now)
lblTimer.Text = String.Format("{0:d2}:{1:d2}:{2:d2}", remainingTime.Hours, remainingTime.Minutes, remainingTime.Seconds)
If intervalTime <= Date.Now Then
tMain.Stop()
End If
End Sub