将两个datetime变量组合成一个

编程入门 行业动态 更新时间:2024-10-24 19:14:45
本文介绍了将两个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变量组合成一个

本文发布于:2023-11-30 11:00:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649736.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   变量   两个   datetime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!