gpt4 book ai didi

asp.net - 将日期和时间加入到 VB.NET 中的 DateTime

转载 作者:行者123 更新时间:2023-12-03 18:31:07 26 4
gpt4 key购买 nike

我正在从数据库中检索数据,其中有单独的日期和时间字段。我想将它们加入到我的 VB.NET 项目中的 DateTime 字段中。
你会建议如何实现这一点?

我试过这个,但它对我不起作用。
“字符串未被识别为有效的日期时间。”

Dim InDate As New DateTime(incident.IncidentDate.Value.Year, incident.IncidentDate.Value.Month, incident.IncidentDate.Value.Day, 0, 0, 0)
Dim InTime As New DateTime(1900, 1, 1, incident.IncidentTime.Value.Hour, incident.IncidentTime.Value.Minute, incident.IncidentTime.Value.Second)


Dim combinedDateTime As DateTime = DateTime.Parse((InDate.ToString("dd/MM/yyyy") + " " + InTime.ToString("hh:mm tt")))

rdtpIncidentDateTime.SelectedDate = combinedDateTime

最佳答案

您可以创建一个新的 DateTime来自 InDate 中的组件的值和 InTime :

Dim combinedDateTime As DateTime = New DateTime( _
InDate.Year, InDate.Month, InDate.Day, _
InTime.Hour, InTime.Minute, InTime.Second _
)

关于asp.net - 将日期和时间加入到 VB.NET 中的 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25578004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com