如何在asp.net中自动计算日期 [英] How to calculate date automatically in asp.net

查看:84
本文介绍了如何在asp.net中自动计算日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有月份,开始日期和结束日期。



月数

开始日期

结束日期



当我没有给出10个月和2015年5月18日开始日期时,结束日期自动计算到+10几个月(即2016年3月18日)

解决方案

尝试:

 DateTime dt; 
int 个月;
if (DateTime.TryParse(日期文本), out dt)&& int .TryParse(monthText, out 个月))
{
dt = dt 。 AddMonths(个月);
...
}


简单示例:



输入参数:

输入日期 - 2015年5月18日DD / MM / YYYY

月数 - 10





 DateTime odt =  new  DateTime( 2015  5  18 ); 


Console.Write(odt + \ n );

Console.WriteLine(odt.AddMonths( 10 ));


< blockquote>

  int  noofmonths =  1 ; 
// 此处您可以根据需要传递日期
DateTime fromdate = new DateTime( 2015 05 ,< span class =code-digit> 18 );
DateTime todate = fromdate.AddMonths(noofmonths);


I have No. of months, start date and end date in my web page.

No. of Months
Start Date
End Date

when i give no of months 10 and start date 18/5/2015, then end date automatically calculate to +10 months (i.e 18/3/2016)

解决方案

Try:

DateTime dt;
int months;
if (DateTime.TryParse(date text), out dt) && int.TryParse(monthText, out months))
   {
   dt = dt. AddMonths(months);
   ...
   }


Simple example :

Input Parameters :
Input Date - 18/5/2015 DD/MM/YYYY
No. of months - 10


DateTime odt = new DateTime(2015, 5, 18);


Console.Write(odt+ "\n");
            
Console.WriteLine(odt.AddMonths(10));


int noofmonths = 1;
          //here you can pass your date as you want
          DateTime fromdate = new DateTime(2015, 05, 18);
          DateTime todate = fromdate.AddMonths(noofmonths);


这篇关于如何在asp.net中自动计算日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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