timers and timespan

G

Guest

I have a form with 3 textboxes.they are: startTime, stopTime, and
elapsedTimeTxt.
I have a timer object on the form named timer1.timer
I have 2 buttons named start and stop respectively.

I need to use the timespan structure to store the start time stop time and
calculate the elapsed time in hours,minutes and seconds then I need to
display all this in my textboxes.

anybody know a code sample to do this?

(it all has to be done in a system class)
EEEEK !!
 
T

thomas wenning

WannaBeProgrammer said:
I have a form with 3 textboxes.they are: startTime, stopTime, and
elapsedTimeTxt.
I have a timer object on the form named timer1.timer
I have 2 buttons named start and stop respectively.

I need to use the timespan structure to store the start time stop time and
calculate the elapsed time in hours,minutes and seconds then I need to
display all this in my textboxes.

anybody know a code sample to do this?

(it all has to be done in a system class)
EEEEK !!

Hi,

try this:
Dim ts As TimeSpan = DateTime.Now.Subtract(startTime)
Dim zeit As String = ts.ToString
zeit = CStr(ts.Hours).PadLeft(2, "0"c) & ":" & _
CStr(ts.Minutes).PadLeft(2, "0"c) & ":" & _
CStr(ts.Seconds).PadLeft(2, "0"c) & vbCrLf &","&_
CStr(ts.Milliseconds).PadLeft(2, "0"c) & vbCrLf

Greeting

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top