且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运动手表

更新时间:2023-02-26 21:35:29

如果您正在寻找经过的时间,您要做的就是保存秒表启动时的当前日期时间,并将其与当前时间进行比较.是停止,或在触发计时器事件时停止.无需自己维持分钟,秒或毫秒.
If you''re looking for elapsed time all you need to do is save the current datetime when the stopwatch is started and compare it to the current datetime when is is stopped, or when the timer event is triggered. No need to maintain minutes, second or milliseconds on your own.


Mark的意思更像是:

What Mark meant was something more like:

''Store the current time when you start your timer
Dim startTime As DateTime
startTime = DateTime.Now;

''Inside Tmr_Tick you can just check how much time has passed
Dim elapsed As TimeSpan
elapsed = startTime - DateTime.Now;



然后,您可以获取该TimeSpan的小时数,分钟数,秒数和毫秒数.

还值得一提的是,标准Timer的分辨率不是很高(您可能已经注意到).您当前正在尝试将间隔"设置为1,但希望的***值接近20ms.

最后一件事,不是添加其他信息来回答您自己的问题,而是应该编辑原始问题,这使其他人可以更轻松地为您提供帮助.



You can then get the number of hours, minutes, seconds and milliseconds fro m that TimeSpan.

It is also worth mentioning that the standard Timer doesn''t have a very high resolution (as you may have noticed). You currently trying to set your Interval to 1 but the best that you can hope for is closer to 20ms.

One last thing, instead of adding an answer to your own question with additional information you should edit your original question, this makes it easier for other people to help you.


马克,我想ms需要增加.你说先保存日期时间,我该怎么办.我尝试仅添加毫秒.请参阅以下代码,但是它不起作用.请问我该怎么办?帮帮我...:((
hi Mark, I think ms need to increase. u said save datetime first, how do i. I try to Add millisecond only. see the following code but it isn''t work. Pls, how do i do ? Help me... :((

Dim tmr As System.Windows.Forms.Timer
   Dim ts1 As New TimeSpan(0, 0, 0, 0)


Dim ms, sec, min As Integer





Private Sub Ticker_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Text = ts1.Seconds & ":" & ts1.Milliseconds
        ms += 15.4
        ts1 = New TimeSpan(0, 0, min, sec, ms)
    End Sub





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'MsgBox("Ok, Let's start")
        tmr.Start()
    End Sub





Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim ts As New TimeSpan(30, 0, 0, 0)
        'tmr = New System.Windows.Forms.Timer
        'tmr.Interval = 1000
        'AddHandler tmr.Tick, AddressOf Ticker_Tick
        'MsgBox("Ok, Let's start")
        'tmr.Start()
        Me.Text = "0:0"
        Dim ts As New TimeSpan(30, 0, 0, 0)
        tmr = New System.Windows.Forms.Timer
        tmr.Interval = 1
        AddHandler tmr.Tick, AddressOf Ticker_Tick
    End Sub



对我来说至关重要,对我至关重要,非常感谢.



Help Me pls, vital for me, Thankz a lot.