我使用 DateTimePicker 来选择一个 dateTime 值,看看我有多少时间直到它为零:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
timeInSeconds = (DateTimePicker1.Value.Subtract(System.DateTime.Now)).ToString
'RichTextBox1.Text = RichTextBox1.Text + vbTab + timeInSeconds.ToString
timeInSeconds = timeInSeconds.Substring(0, timeInSeconds.LastIndexOf("."))
End Sub
上面的 RichTextbox 显示我大约每 30 秒失去一秒:
23:59:47.4060217
23:59:46.3939638
23:59:45.3799058
23:59:44.3648477
23:59:43.3517898
23:59:42.3377318
23:59:41.3236738
23:59:40.3096158
23:59:39.2955578
23:59:38.2814998
23:59:37.2674418
23:59:36.2533838
23:59:35.2393258
23:59:34.2242677
23:59:33.2112098
23:59:32.1981518
23:59:31.1830938
23:59:30.1690358
23:59:29.1549778
23:59:28.1409198
23:59:27.1268618
23:59:26.1128038
23:59:25.0997458
23:59:24.0856878
23:59:23.0716298
23:59:22.0575718
23:59:21.0435138
23:59:20.0284558
23:59:19.0143978
**23:59:18.0013398
23:59:16.9872818**
所以使用
timeInSeconds = timeInSeconds.Substring(0, timeInSeconds.LastIndexOf("."))
从 23:59:18 到 23:59:16
为什么呢?我做错了什么?是不是那个时候
(DateTimePicker1.Value.Subtract(System.DateTime.Now)).ToString
发生我失去的事情?
计时器设置为每秒钟进行一次更改。
我该怎么做才能获得正确的结果?
提前致谢!