复制代码 代码如下:
//计算天数
    protected int getDays(DateTime date1, DateTime date2)
    {

        int days = 0;
        if (date1.Year == date2.Year)
        {
            if (date1.Month < date2.Month)
            {
                days = (date2.Day - date1.Day) + (date2.Month - date1.Month) * 30;
            }
            if (date2.Month == date1.Month)
            {
                days = date2.Day - date1.Day;
            }
        }
        else
        {
            DateTime date3 = Convert.ToDateTime(date1.Year + "- 12 - 31");
            DateTime date4 = Convert.ToDateTime(date2.Year + "- 01 - 01");
            int day1 = 0;
            if (date1.Month < date3.Month)
            {
                day1 = (date3.Day - date1.Day) + (date3.Month - date1.Month) * 30;
            }
            if (date3.Month == date1.Month)
            {
                day1 = date3.Day - date1.Day;
            }

 

            int day2 = 0;
            if (date4.Month < date2.Month)
            {
                day2 = (date2.Day - date4.Day) + (date2.Month - date4.Month) * 30;
            }
            if (date4.Month == date2.Month)
            {
                day2 = date2.Day - date4.Day;
            }

            days = day1 + day2;

        }
        return days;
    }

标签:
日期,天数

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“asp.net根据日期算出天数的小例子”

暂无“asp.net根据日期算出天数的小例子”评论...