我有一个变量,用于存储用户输入的时间。我收到一个错误,说它无法将它从双精度转换为日期。我该怎么做呢?
基本上我需要从用户那里抽出时间并将其转换为分钟。我不知道怎么做。
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtTimeIn.TextChanged, txtTimeIn.TextChanged
Dim m_decTimeIn As DateTime
m_decTimeIn = Val(txtTimeIn)
End Sub
答案 0 :(得分:5)
Dim myDateTime As DateTime = DateTime.FromOADate(myDouble)
答案 1 :(得分:0)
Val
函数在此特定重载中将String
值转换为Double
。此类型不能转换为DateTime
,因此编译器会发出错误。
要将String
转换为日期而使用Datetime.Parse
而不是
m_decTimeIn = DateTime.Parse(txtTimeIn.Text)