如何添加两个日期? [英] How to add two dates?

查看:104
本文介绍了如何添加两个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在<appSettings>标记下的web.config文件中提到了一个自定义日期时间,如下所示.

In my application, I have mentioned a custom datetime in my web.config file under <appSettings> tag as shown below.

<appSettings>
<add key="DateTime" value="01/01/0001 01:01:01"/>
</appSettings>


所以那个时间我想在后面的代码中添加当前日期时间.

谁能说怎么做?

谢谢


So that time I want to add with current datetime in code behind.

Can any one say how to do this?

Thanks

推荐答案

添加两个日期后您会得到什么?
3月3日+下星期二等于多少?我不知道,我也不认为你知道.因为很傻.就像在光年中添加橘子一样!

考虑一下:您实际上要实现什么?
What do you expect to get when you add two dates?
What is 3rd March + next Tuesday equal to? I don''t know, and I don''t think you do. Because it is silly. It is like adding oranges to lightyears!

Think about it: what are you actually trying to achieve?


您使用^ ]和 TimeSpan [
You use DateTime[^] and TimeSpan[^] structs

But you cannot add a DateTime to another DateTime. You can add a TimeSpan to a DateTime.

DateTime now = DateTime.Now;
DateTime arrive = now + new TimeSpan(2, 30, 0); // Add 2 hours and 30 min.



add key="DateTime"更改为TimeSpan.



Change add key="DateTime" to TimeSpan.


按照此处 [^ ] .
然后使用DateTime.Add方法将此值添加到另一个日期.
Read this date as described here[^].
Then add this value to another date using the DateTime.Add method.


这篇关于如何添加两个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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