我想製作一個簡單的程序,將時間轉換爲hh:mm:ss格式。但對於某些特定的輸入值,它會產生不正確的時間格式。這是我曾嘗試:程序將時間以秒爲單位轉換爲hh:mm:ss格式
Public Class Form1
Dim Hours, Minutes, Seconds As Integer
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
lblHours.Text = "00"
lblMinutes.Text = "00"
lblSeconds.Text = "00"
txtTimeSeconds.Text = ""
txtFormattedTime.Text = ""
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click
Seconds = Integer.Parse(txtTimeSeconds.Text)
Hours = Seconds/3600
Seconds = Seconds Mod 3600
Minutes = Seconds/60
Seconds = Seconds Mod 60
lblHours.Text = Hours.ToString.PadLeft(2, "0"c)
lblMinutes.Text = Minutes.ToString.PadLeft(2, "0"c)
lblSeconds.Text = Seconds.ToString.PadLeft(2, "0"c)
txtFormattedTime.Text = Hours.ToString.PadLeft(2, "0"c) & ":" & Minutes.ToString.PadLeft(2, "0"c) & ":" & Seconds.ToString.PadLeft(2, "0"c)
End Sub
End Class
它的工作原理,當輸入值爲30:
當輸入值是31它不工作:
我做錯了什麼?我該如何解決這個問題?
它的工作原理。謝謝 – 2012-01-15 11:00:57