感谢这位兄弟的意见,
本例程时间范围从1901年春节开始到2100年春节结束(不包含该天),哈哈,如果有1900年以前和2099年以后的农历信息表的话,也可以继续添加的
第二个问题经确实,修改如下:
int MonthAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
BOOL LunarCalendar(int year,int month,int day, unsigned int *returnDay)
{
unsigned int LunarCalendarDay=0;
int Spring_NY,Sun_NY,StaticDayCount;
int index,flag;
int iEmbolism=0;
//Spring_NY 记录春节离当年元旦的天数。
//Sun_NY 记录阳历日离当年元旦的天数。
if( ((LunarCalendarTable[year-1901] & 0x0060) >> 5) == 1)
Spring_NY = (LunarCalendarTable[year-1901] & 0x001F) - 1;
else
Spring_NY = (LunarCalendarTable[year-1901] & 0x001F) - 1 + 31;
Sun_NY = MonthAdd[month-1] + day - 1;
if( (isleap(year)) && (month > 2))
Sun_NY++;
//StaticDayCount记录大小月的天数 29 或30
//index 记录从哪个月开始来计算。
//flag 是用来对闰月的特殊处理。
//判断阳历日在春节前还是春节后
if (Sun_NY >= Spring_NY)//阳历日在春节后(含春节那天)
{
Sun_NY -= Spring_NY;
month = 1;
index = 1;
flag = 0;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
while(Sun_NY >= StaticDayCount)
{
Sun_NY -= StaticDayCount;
index++;
if(month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20) )
{
flag = ~flag;
if(flag == 0)
{
month++;
iEmbolism = 0;
}
else
{
iEmbolism = 1;
}
}
else
month++;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount=29;
else
StaticDayCount=30;
}
day = Sun_NY + 1;
}
else//阳历日在春节前
{
Spring_NY -= Sun_NY;
year--;
month = 12;
if ( ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20) == 0)
index = 12;
else
index = 13;
flag = 0;
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
while(Spring_NY > StaticDayCount)
{
Spring_NY -= StaticDayCount;
index--;
if(flag == 0)
month--;
if(month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20))
{
flag = ~flag;
if (flag != 0)
{
iEmbolism = 1;
}
else iEmbolism = 0;
}
if( ( LunarCalendarTable[year - 1901] & (0x80000 >> (index-1)) ) ==0)
StaticDayCount = 29;
else
StaticDayCount = 30;
}
day = StaticDayCount - Spring_NY + 1;
}
LunarCalendarDay |= day;
LunarCalendarDay |= (month << 6);
*returnDay = LunarCalendarDay;
if((month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20)) && iEmbolism==1)
return TRUE;
else
return FALSE;
}
再次感谢,希望更多的朋友来,完善代码
阅读(996) | 评论(0) | 转发(0) |