计算一年中的第几天

include leap year

int dayOfYear(int year, int month, int day)
{
    int months[13] = {0,31,30,28,31,30,31,31,30,31,30,31}, i, days = 0;
    if( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) // is leap year
        months[2] = 29;

    for(i = 1; i < month; i++)
        days += months[i];
    days += day;

    return days;
}

 

posted @ 2013-11-04 15:35  alexeyqian  阅读(222)  评论(0编辑  收藏  举报