星期计算函数

int is_leap_year( int year )
{
    int    iRet;
    
    iRet = 0;
    
    if( 0 == ( year % 400 ) )
    {
        iRet = 1;
    }
    else if( ( 0 == ( year % 4 ) ) && ( 0 != ( year % 100 ) ) )
    {
        iRet = 1;
    }
    
    return( iRet );
}
int get_week( int year,int month,int day )
{
    
    int iWeek, iConst, iYear;
    int aiRate[13] = { 0, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
    
    iYear = year % 400;
    
    if(is_leap_year( year ) && ( month < 3 ) )
    {
        iConst = 5;
    }
    else
    {
        iConst = 6;
    }
    
    iWeek = ( iYear + iYear / 4 - iYear / 100 + aiRate[month] + day + iConst ) % 7;
    
    return( iWeek );
}

发布了71 篇原创文章 · 获赞 23 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/ssmile/article/details/7515170