vb.net 定时器的显示值 - VB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13745129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:28:02  来源:igfitidea点击:

Display Value of timer - VB

vb.net

提问by Ds.109

I can't figure out how to simply display to value of a timer after it's stopped in VB.

我不知道如何在 VB 中停止后简单地显示计时器的值。

I tried stuff like MsgBox(Val(Timer2))but it's not that simple apparently.

我尝试过类似的东西,MsgBox(Val(Timer2))但显然没有那么简单。

回答by Steve

Perhaps the stopwatch class would work for you:

也许秒表课程对你有用:

    Dim sw As New Stopwatch
    sw.Start()
    'do something, for example:
    Threading.Thread.Sleep(1000)
    sw.Stop()
    MessageBox.Show(sw.ElapsedMilliseconds)

回答by Kratz

I think what you want is this,

我想你想要的是这个

Dim StartTime = DateTime.Now()

'Do race stuff



Dim EndTime = DateTime.Now()

Dim ElapsedSeconds = EndTime.Subtract(StartTime).TotalSeconds

回答by prprcupofcoffee

Timers don't do that. But you can use various date/time functions to do the same thing.

计时器不会那样做。但是您可以使用各种日期/时间函数来做同样的事情。

Dim startTime As DateTime
Dim elapsed As DateTime
' ...
Timer2.Start()
startTime = Now

' after race finishes, then:
elapsed = Now - startTime

This gives you a TimeSpanobject.

这给了你一个TimeSpan对象。

or

或者

Dim startTime As Integer = Environment.TickCount
' ...
Dim elapsed As Integer = Environment.TickCount - startTime

This gives you an overall time in milliseconds.

这为您提供了以毫秒为单位的总体时间。