判斷一年中某一天是這一年的第幾天的函式介面

田園詩人之園發表於2015-08-10
#define ret_ok  0
#define ret_err 1

int a[] = {31, 28, 31, 30, 31, 30, 31,31, 30, 31, 30, 31};

int judge_day(int Year, int Month, int Day, int *result_day)
{
    int Total = 0;
    int i = 0;

    if( (((Year%400) == 0) || ((Year%4) == 0)) && ((Year %100) != 0))//如果是閏年,那麼2月份為29天
    {
        a[1] = 29;
    }
    for(i=0;i<Month-1;i++)
    {
        Total += a[i];
    }
    Total += Day;
    *result_day = Total;

    return ret_ok;
}

相關文章