C# 判断月初月末

DateTime now = DateTime.Now;
            DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1);
            DateTime lastDayOfMonth = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month));

            if (now.Date == firstDayOfMonth.Date)
            {
                MessageBox.Show("当前时间是月初");
            }
            else if (now.Date == lastDayOfMonth.Date)
            {
                MessageBox.Show("当前时间是月末");
            }
            else
            {
                MessageBox.Show("当前时间既不是月初也不是月末");
            }

 

posted @ 2025-09-04 19:43  大da脸  阅读(15)  评论(0)    收藏  举报