美文网首页IOS 超级无敌
计算每个月的天数

计算每个月的天数

作者: 代码干货 | 来源:发表于2016-03-15 09:47 被阅读64次

<pre>-(NSInteger)daysOfyear:(NSInteger)year month:(NSInteger)month
{
int days = 0;

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
    days = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
    days = 30;
}
else
{ // 2月份,闰年29天、平年28天
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
    {
        days = 29;
    }
    else
    {
        days = 28;
    }
}

return days;

}</pre>

相关文章

网友评论

    本文标题:计算每个月的天数

    本文链接:https://www.haomeiwen.com/subject/eszflttx.html