我正在嘗試減去兩次。減去VB.net中的時間
Sub notifier(checkouttime As Label)
Dim checktime As New DateTime(checkouttime.Tag)
Dim currenttime As New DateTime(DateAndTime.TimeOfDay.ToString("hh:mm:ss"))
Dim balance As TimeSpan = checktime - currenttime
End Sub
我checkouttime.tag下具有這種格式的時間值「HH:MM:SS」
,我必須得到當前時間與今天相同的格式,我實現它,但當我需要扣除他們時,我收到一個錯誤。
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "08:00:58" to type 'Long' is not valid.
在此先感謝
它有助於編譯選項嚴格上的代碼了一段時間,以避免陷阱這樣。你需要'Dim checktime As New DateTime(CStr(checkouttime.Tag))' –