从秒表返回十分之一秒和百分之一秒
所以我越来越接近让计时器按照我想要的方式工作,但有一个小问题。
我发现以下关于返回毫秒和纳秒的帖子: 如何将秒表刻度转换为纳秒、毫秒和秒?
但我想做的是在需要时仅显示百分之一秒的十分之一。
我有以下代码:
Private Sub TotalTimer_Tick(sender As System.Object, e As System.EventArgs) Handles TotalTimer.Tick
Dim elapsed As TimeSpan = Me.matchStopwatch.Elapsed
Me.MatchClockLbl.Text = String.Format("{0:0}:{1:00}:{2:00}.{3:###}", _
Math.Floor(elapsed.TotalHours), _
elapsed.Minutes, _
elapsed.Seconds, _
(elapsed.Milliseconds / 100))
End Sub
现在我尝试将代码部分从 {3:000} 更改为 {3:0} 或 {3:00} 但所做的只是更改格式,它实际上并没有删除第 1000 位数字或千位数字,它们仍然会出现。
我进一步在 MSDN 上找到了这一点:
http://msdn.microsoft。 com/en-us/library/ee372287.aspx#fSpecifier
但我不断收到 sf 或 s/f 或其他不正确的内容。
编辑:添加到代码的修改版本中,感谢 Oded。现在的新问题是标签喜欢偶尔闪烁多余的数字。
So I'm getting closer and closer to making the timer work the way I want it to, with one small problem.
I found the following post about returning millisecond and nanosecond:
How do you convert Stopwatch ticks to nanoseconds, milliseconds and seconds?
But what I'm trying to do is show only the 10ths of 100ths of a second when desired.
I have the following code:
Private Sub TotalTimer_Tick(sender As System.Object, e As System.EventArgs) Handles TotalTimer.Tick
Dim elapsed As TimeSpan = Me.matchStopwatch.Elapsed
Me.MatchClockLbl.Text = String.Format("{0:0}:{1:00}:{2:00}.{3:###}", _
Math.Floor(elapsed.TotalHours), _
elapsed.Minutes, _
elapsed.Seconds, _
(elapsed.Milliseconds / 100))
End Sub
Now I tried to change the part of code from {3:000} to {3:0} or {3:00} but all this does is change format, it doesn't actually remove the 1000ths digit or 1000ths digit, they still show up.
I further found this on the MSDN:
http://msdn.microsoft.com/en-us/library/ee372287.aspx#fSpecifier
But I keep getting s.f or s/f or something that's not right.
EDIT: Added in the modified version of the code, thanks Oded. The new problem now is that the label likes to flicker the extra digits once in a while.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
毫秒
除以 10 即可得到十分之一秒,再除以 100 即可得到十分之一秒。这是通过整数除法实现的 - 本质上是丢弃最低有效数字并假设
Milliseconds
返回最多 3 位数字。Divide
Milliseconds
by 10 to get 100th of a second and by 100 to get 10th of a second.This works by integer division - essentially throwing away the least significant digits and assumes
Milliseconds
returns at most 3 digits.