DateTime.IsLeapYear 方法判断是否是闰年,DaysInMonth判断一个月有几天,Addday取得前一天的日期GetYesterDay...

一:DateTime.IsLeapYear 方法判断是否是闰年 

二:代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace GetDays

{

    public partial class Frm_Main : Form

    {

        public Frm_Main()

        {

            InitializeComponent();

        }

 

        private void btn_Get_Click(object sender, EventArgs e)

        {

            if (DateTime.IsLeapYear(int.Parse(//判断是否为闰年,IsLeapYear返回bool指定的年份是否为闰年的指示

                DateTime.Now.ToString("yyyy"))))

            {

                MessageBox.Show("本年有366天","提示!");//显示天数信息

            }

            else

            {

                MessageBox.Show("本年有365天", "提示!");//显示天数信息

            }

        }

    }

}

 

三:DaysInMonth判断一个月有几天,截图

 

四:代码

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace DaysInMonth

{

    public partial class Frm_Main : Form

    {

        public Frm_Main()

        {

            InitializeComponent();

        }

 

        private void btn_Get_Click(object sender, EventArgs e)

        {

            int P_Count = DateTime.DaysInMonth(//获取本月的天数,返回指定年和月中的天数。

                DateTime.Now.Year, DateTime.Now.Month);

            MessageBox.Show("本月有" +//显示本月的天数

                P_Count.ToString() + "天", "提示!");

        }

    }

}

 

五:Addday取得前一天的日期GetYesterDay,截图

 

六:代码

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace GetYesterDay

{

    public partial class Frm_Main : Form

    {

        public Frm_Main()

        {

            InitializeComponent();

        }

 

        private void btn_GetYesterday_Click(object sender, EventArgs e)

        {

            MessageBox.Show(//显示前一天日期

                "昨天是:" + DateTime.Now.AddDays(-1).

                ToString("yyyy年M月d日"), "提示!");

        }

    }

}

 

转载于:https://www.cnblogs.com/taofx/p/4137665.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值