2012-12-01 100 views
0

我想添加一個打印經過時間的標籤,就像普通時鐘一樣(秒數達到「59」,然後將「1」min加到計數器),但是當秒數達到數字時,我的時間跨度增加分鐘數「30」......我做錯了什麼?Timespan出錯

Dim ElapsedTime As TimeSpan 

While log_button.Text = "Stop logger" 
      ElapsedTime = Now().Subtract(StartTime) 
      Label5.Text = String.Format("Minutos transcurridos: {0:00}:{1:00}", CInt(ElapsedTime.TotalMinutes) Mod 60, CInt(ElapsedTime.TotalSeconds) Mod 60) 
      Application.DoEvents() 
End While 

我得到一個錯誤的增量是這樣的:

enter image description here

enter image description here

00:01

...

00:28

00:29

00:30

01:31

01:32

等等

回答

2

那是因爲你是圓代表總浮點數分鐘。當數字達到0.5將四捨五入到1

使用Floor方法截斷號:

CInt(Math.Floor(ElapsedTime.TotalMinutes)) Mod 60 

您還可以使用Minutes屬性,但這一切:

ElapsedTime.Minutes