我想在 vb.net 中做 am/pm if 陳述句,但我不知道該怎么做
If txtHourEnter.Text < "12" Then
lblTimeIn.Text = txtHourEnter.Text ":" txtMinEnter.Text "AM"
ElseIf txtHourEnter.Text >= "12" Then
lblTimeIn.Text = txtHourEnter.Text ":" txtMinEnter.Text "PM"
End If
我試過了,但每當我輸入 2 時,它會說 pm,如果我輸入 1,它會說 am
uj5u.com熱心網友回復:
不要嘗試直接使用Text
控制元件中的屬性。這只會讓計算變得困難。始終將文本轉換為可用于計算的資料型別,然后進行計算,最后再轉換回可顯示的資料型別。
嘗試這個:
Dim entered As String = txtHourEnter.Text ":" txtMinEnter.Text
Dim time As DateTime
Dim display As String = "Invalid entry"
If DateTime.TryParse(entered, time) Then
display = time.ToString("h:mm tt")
End If
lblTimeIn.Text = display
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/536763.html
標籤:网络
上一篇:Linux切換賬戶(或ssh遠程)執行QT程式無法輸入中文
下一篇:電腦優化與清理