|
-
Aug 30th, 2009, 07:11 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Stopwatch Help
I am using a stop watch to get the elapsed minutes and seconds which will then be displayed to user. How to I go about getting the elapsed time in the following format:
00:00
-
Aug 30th, 2009, 07:39 AM
#2
Fanatic Member
Re: Stopwatch Help
By stopwatch I assume you mean the timer Object. That is not designed to give you the time between two events. It is designed to trigger after a certain amount of time - say you want a 10 second pause.
What I would do is use the Now() function to get the current time at the start of the process and end of the process. Then used the DateDiff function to determine the time difference between the two times in Seconds. Once you have the number of seconds, you do a little math to figure out how many minutes and seconds, then format that, just building it up. You will have to format you minutes and seconds to ensure they give you two numbers. You can use a Format string for that.
I hope that helps.
-
Aug 30th, 2009, 07:53 AM
#3
Thread Starter
Addicted Member
Re: Stopwatch Help
Ok cool i'm actually using the stopwatch class not a timer. I can get the time but am not sure about how to format the time.
-
Aug 30th, 2009, 07:55 AM
#4
Re: Stopwatch Help
Hey,
Have you looked at the documentation for the StopWatch Class?
http://msdn.microsoft.com/en-us/libr...stopwatch.aspx
It would appear to tell you how to do exactly what you want.
Gary
-
Aug 30th, 2009, 09:18 AM
#5
Hyperactive Member
Re: Stopwatch Help
Heres is some code for what i used. The format i used was Hour:Minute:Seconds:Millisecond
Code:
Private watch As Diagnostics.Stopwatch
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Timer1.Enabled = True
Me.watch = Diagnostics.Stopwatch.StartNew
Me.Timer1.Start()
End Sub
Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Timer1.Stop()
Timer1.Dispose()
Timer1.Enabled = False
lblTime.Text = ("00:00")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim elapsed As TimeSpan = Me.watch.Elapsed
Me.lblTime.Text = String.Format("{0:00}:{1:00}", _
elapsed.Seconds, _
elapsed.Milliseconds)
End Sub
Ive Changed it for your 00:00
-
Aug 30th, 2009, 11:31 AM
#6
Thread Starter
Addicted Member
Re: Stopwatch Help
Ok thanks guys problem solved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|