您的位置:首页 > 编程语言 > C#

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

2014-01-08 09:46 267 查看
#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# 月份 确定 每月 天数