这个混乱的原因是由于数据库在哪里我拉数据,他们有两个不同的列存储实际的日期和时间。这是代码:
DateTime date = Convert.ToDateTime(dTable.Rows [i] [0]); DateTime time = Convert.ToDateTime(dTable.Rows [i] [1]); DateTime newDateTime = new DateTime();newDateTime需要设置完整的datetime集,其中date分数在date变量中,时间分数在时间变量中。
如果有人可以帮助我会很开心:)
解决方案应该这样做:
newDateTime = date.Date + time.TimeOfDay;
I have a little problem that I just cannot seem to solve. I have two datetime variables, the important data in the one is the year, month and day. The other datetime variable stores the hour, minute and second.
The reason for this chaos is due to the database where I'm pulling the data from, where they have two different columns to store the actual date and the time. Here is the code:
DateTime date = Convert.ToDateTime(dTable.Rows[i][0]); DateTime time = Convert.ToDateTime(dTable.Rows[i][1]); DateTime newDateTime = new DateTime();The newDateTime need to have the complete datetime set, where the date fraction is in the date variable and the time fraction is in the time variable.
If anyone can help out I will be very happy :)
解决方案This should do:
newDateTime = date.Date + time.TimeOfDay;