万年历算法分析:万年历算法一、 阳历算法具体算法见函数Void get_solar_day_date(void),这样阳历日历的星期排法就确定了。表1:月份 1 2 3 4 5 6 7 8 9 10 11 12 闰年 31 29 31 30 31 30 31 31 30 31 30 31 非闰年 31 28 31 30 31 30 31 31 30 31 30 31 变量定义:Public:Unsigned int temp_total_day;Unsigned char gc_solar_calendar_year;Unsigned char gc_solar_calendar_month;Unsigned char gc_solar_calendar_date;Unsigned char gc_lunar_calendar_year;Unsigned char gc_lunar_calendar_month;Unsigned char gc_lunar_calendar_date;Unsigned char start_day_of_week;说明:函数get_solar_day_date(void)的输入变量:gc_solar_calendar_year和gc_solar_calendar_month输出变量:start_day_of_week和temp_total_dayVoid get_solar_day_date(void){unsigned char temp01;/*------calculate what day is the day of the current month and year. Mon~Sun?---*//*条件初始化二次,减少运算数据量. temp_total_day 是int型变量*/start_day_of_week = 2; temp_total_day = 0;calculate_temp = 1;if(gc_solar_calendar_year > 99){start_day_of_week = 6;calculate_temp = 100;}for(temp01 = calculate_temp; temp01<gc_solar_calendar_year; temp01++){ if(temp01%4 == 0){start_day_of_week +=2;temp_total_day += 366; }else {start_day_of_week +=1;temp_total_day += 365;}}for(temp01 = 1;temp01<gc_solar_calendar_month;temp01++){ switch(temp01){case 1,3,5,7,8,10,12: start_day_of_week +=3;temp_total_day +=31;break;case 2: if(((gc_solar_calendar_year%4) == 0)&&(gc_solar_calendar_year != 200)){start_day_of_week +=1; temp_total_day +=29;}else {start_day_of_week +=0;temp_total_day +=28;} break;case 4,6,9,11: start_day_of_week +=2; temp_total_day +=30; break;}}start_day_of_week %=7;/*-end of calculate what day is the day(Mon~Sun?) and total day --*/
猜您喜欢
推荐内容
开源项目推荐 更多
热门活动
热门器件
用户搜过
随便看看
热门下载
热门文章
热门标签
评论