将两个datetime变量组合成一个 [英] Combine two datetime variables into one

查看:131
本文介绍了将两个datetime变量组合成一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点问题,我似乎无法解决。我有两个datetime变量,一个重要的数据是年,月和日。其他datetime变量存储小时,分和秒。



这个混乱的原因是由于数据库在哪里我拉数据,他们有两个不同的列存储实际的日期和时间。这是代码:

  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;

这篇关于将两个datetime变量组合成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆