我正从DB中检索数据,其中有一个单独的日期和时间字段.我想将它们加入到我的VB.NET项目中的DateTime字段中.你会怎么建议完成这个?
我试过这个,但它不适合我."字符串未被识别为有效的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
Run Code Online (Sandbox Code Playgroud)
你可以创建一个新的DateTime从组件值InDate和InTime:
Dim combinedDateTime As DateTime = New DateTime( _
InDate.Year, InDate.Month, InDate.Day, _
InTime.Hour, InTime.Minute, InTime.Second _
)
Run Code Online (Sandbox Code Playgroud)
DateTime公开了一个名为DateTime.TimeOfDay的方法
您只需使用DateTime.Add将时间附加到日期即可.
Dim dateAndTime As DateTime = myDate.Add(myTime.TimeOfDay)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10610 次 |
| 最近记录: |