打印

我做的万年星期函数,看看有没有问题

[复制链接]
1225|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
foxfox|  楼主 | 2008-11-6 15:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    算某年某月某日是星期几?
   
   要算公元后的某一天是星期几,首先要知道历史上第一个星期日是哪一天。
   去看看历史,公元0001年12月25日是耶稣诞生日,这一天是真正的礼拜天。
    
  当前星期?=以耶稣生日做基数和当前距离**开始的日期的差值%7


unsigned char calculate_week(unsigned int year, unsigned char moon,unsigned char day)
{
    unsigned char month_table[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};  //平年月表
    unsigned long  Jesus;                     //耶稣生日距离**年开始的天数
    unsigned long    current_day_history;         //当前日期距离**年开始的天数
    unsigned int   this_year;                   //
    unsigned char i;                           //遍历变量
    for(i=0,Jesus=0;i<12,i++){
        Jesu+=month_table;      //计算耶稣生日距离**年开始的天数
    }
    if(((year%4==0)&&(year%100))||(year%400==0)){                         
        month_table[2]=29;           ////本年是闰年,     修改闰年二月份天数
    }
    for(i=0,this_year=0;i<moon,i++){
        this_year+=month_table;                //
    }
    this_year=this_year+day;                          //是今年的第xxx天
    current_day_history=(unsigned long)((year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+this_year))
    
    if(current_day_history<Jesus){
        current_day_history=Jesus-current_day_history;      //是在耶稣生日前的话
        return (7-current_day_counter%7);                   //是在耶稣生日前的话
    }else{
        current_day_history=current_day_history-Jesus;      //是耶稣生日之后
        return(current_day_counter%7);
    }
}

相关帖子

沙发
hgjinwei| | 2008-11-6 19:59 | 只看该作者

绝对有问题,编译都通不过!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

57

帖子

1

粉丝