C# 根据月份来确定每月的最大天数

        #region 根据月份来确定每月的最大天数
	//月份为两位
        private int SetDate(string time)
        {
            int intYear;
            int intMonth;
            int intDay;           
            string year = time.Substring(0,4);
            string month = time.Substring(4,2);
            int.TryParse(year, out intYear);
            int.TryParse(month, out intMonth);
            if (intMonth == 02)
            {
                if (intYear % 400 == 0 || (intYear % 4 == 0 && intYear % 100 != 0))//判断是不是闰年  
                {
                    intDay = 29;
                }
                else
                {
                    intDay = 28;
                }
            }
            switch (intMonth)
            {
                case 04:
                case 06:
                case 09:
                case 11: intDay = 30; break;
                default: intDay = 31; break;
            }
            return intDay;
        }
        #endregion

你可能感兴趣的:(C#,天数,月份,每月,确定)