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日"), "提示!");
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM