| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1130 人关注过本帖
标题:求助:在网上看到TC程序的阴历转农历程,求高手改编VFP中用
只看楼主 加入收藏
qq895231555
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-1-4
结帖率:50%
收藏
 问题点数:0 回复次数:3 
求助:在网上看到TC程序的阴历转农历程,求高手改编VFP中用
void  solar_lunar(unsigned int kp_year,unsigned char kp_month,unsigned char kp_day)
 */

#include<stdio.h>
/*
阳历1900.1.1
在阳历为1900.1.31  时阴历为1900.1.1 即1900年正月初一
*/

unsigned int solar_year=0,lunar_year=0;
unsigned char solar_month=0,lunar_month=0;
unsigned  int solar_day=0,lunar_day=0;

/*1900-2050年的农历数据
数据格式说明:
5位十六进制数字 例:04bd8
  1    位: 1表示闰月30天,0表示29天
2、3、4位: 转换二进制为:0100 1011 1101(1为30天,0为29天)
           04bd8表示为(13个月):29,30,29,29,30,29,30,30,30(闰8月),30,30,29,30;
  5    位: 如果有闰月,则为月份,没有则为0*/
unsigned long int lunar_info[]=
{
    0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
    0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
    0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
    0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
    0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
    0x06ca0,0x0b550,0x15355,0x04da0,0x0a5b0,0x14573,0x052b0,0x0a9a8,0x0e950,0x06aa0,
    0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
    0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b6a0,0x195a6,
    0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,  //1980
    0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
    0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,  //2004 07552
    0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
    0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530, //2028
    0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
    0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0,
    0x14b63
};
//#############################################
//---------------------------------------------
unsigned char get_leap_month(unsigned int lunar_year) //确定是否存在农历的闰月 并返回闰月
{
    return lunar_info[lunar_year-1900]&0xf;
}
//---------------------------------------------
unsigned char get_leap_month_day(unsigned int lunar_year)  //若存在闰月,返回闰月的天数,30?29
{
    if(get_leap_month(lunar_year))
        return(  ( (lunar_info[lunar_year-1900]) & 0x10000 ) ? 30:29 );
    else
        return(0);
}
//---------------------------------------------
unsigned char get_lunar_month_total(unsigned int lunar_year, unsigned char lunar_month) //确定农历当月天数,30?29
{
    return( (lunar_info[lunar_year-1900] & (0x10000>>lunar_month) ) ? 30:29 );
}
//---------------------------------------------
unsigned int get_lunar_year_total(unsigned int lunar_year) // 农历当年总天数,354?355 384 383
 {
    /*sum=12*29 */   //12个月 29天一月
    unsigned int sum=348;
    unsigned int i;
     for(i=0x8000;i>0x8; i>>=1)
         sum+=(lunar_info[lunar_year-1900]&i)?1:0;  //把大月的1加进去
    return(sum+get_leap_month_day(lunar_year));    //判断这年是否有闰月
 }
//---------------------------------------------
//#############################################

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//---------------------------------------------
unsigned int leap(unsigned int year)  //判断是否为闰年
{
    if( (year%4==0 &&year%100!=0) || year%400==0 )
        return 366;
    else
        return 365;
}

//--------------------------------------
unsigned char day(unsigned int year ,unsigned char month) //判断当年当月天数
{
    if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
        return 31;
    if(month==4||month==6||month==9||month==11)
        return 30;
    if(month==2&&leap(year)==366)
        return 29;
    else
        return 28;
}
//-------------------------------------------
//计算1900.1.1 到  输入年月的天数
unsigned int get_solar_total(unsigned int solar_year, unsigned char solar_month)
{
    unsigned int total;
    unsigned int temp_num;
    total=0;
    for(temp_num=1900;temp_num<solar_year;temp_num++)
        total+=leap(temp_num);
    for(temp_num=1;temp_num<solar_month;temp_num++)
        total+=day(solar_year,temp_num);
    return total;
}
//----------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
unsigned char  solar_lunar(unsigned int kp_year,unsigned char kp_month,unsigned char kp_day)/* 输入阳历时期 年    日 */
{
    unsigned int total_day=0;/*记录农历1900.1.1日到今天相隔的天数 */
    unsigned char run_yue_flag=0,run_yue=0,year_flag=0;

    if(kp_year<1900 || kp_year>2050 || kp_month>12 || kp_month==0 || (kp_year==1900 && kp_month==1) )
        return 0;
    if(kp_day>day(kp_year,kp_month) || kp_day==0)
        return 0;

    total_day=get_solar_total( kp_year, kp_month)+kp_day-30; /* 阳历从1900.1.31(农历1900.1.1)到今天的总天数(减30 实际少了一天)。 */
    lunar_year=1900;
    while(total_day>385) //385大于一年  留出一年多的时间用于条件计算
    {
        total_day-=get_lunar_year_total(lunar_year); //
        lunar_year++;
    }
    if(total_day>get_lunar_year_total(lunar_year))  //排除lunar_year有闰月的情况
    {
        total_day-=get_lunar_year_total(lunar_year);
        lunar_year++;

    }
    run_yue=get_leap_month(lunar_year);  //当前闰哪个月
    if(run_yue)
        run_yue_flag=1; //有闰月则一年为13个月
    else
        run_yue_flag=0;  //没闰月则一年为12个月

    if(total_day==0)   //刚好一年
    {
        lunar_day=get_lunar_month_total(lunar_year,12);
        lunar_month=12;
    }
    else
    {
        lunar_month=1;
        while(lunar_month<=12)
        {
                if( run_yue_flag==1 && lunar_month==(run_yue+1) )  //闰月处理
                {
                        if(total_day>get_leap_month_day(lunar_year))
                        {
                            total_day-=get_leap_month_day(lunar_year);  //该年闰月天数

                        }
                         //lunar_month--;
                         run_yue_flag=0;
                         continue;

                }
                if( total_day> get_lunar_month_total(lunar_year,lunar_month ) )
                {
                        total_day=total_day-get_lunar_month_total(lunar_year,lunar_month);  //该年该月天数
                        lunar_month++;
                }
                else
                {
                    lunar_day=total_day;
                    break;
                }
        }
    }
}

//--------------------------------------------
void main(void)
{

    while(1)
    {


        printf("\nplease input  Y M D:");
        scanf("%d",&solar_year);
        scanf("%d",&solar_month);
        scanf("%d",&solar_day);
        solar_lunar(solar_year,solar_month,solar_day);
        printf("\nlunar_year:%u",lunar_year);
        printf("\nlunar_month:%u",lunar_month);
        printf("\nlunar_day:%u",lunar_day);
        getch();
    }
}



本文来自CSDN博客,转载请标明出处:http://blog.
搜索更多相关主题的帖子: 阴历 历程 VFP 
2010-02-12 21:15
qq895231555
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-1-4
收藏
得分:0 
附:这是另一网友的VFP程序,望高手加以改进。


FUNCTION NLTOYL
*函数调用格式: 阴历到阳历(年、月、日),参数值均为数值型
*返回值:日期型
PARAMETERS obNL_year,obNL_month,obNL_day &&传进农历的:年(1990--2049、月(1--2)、日(1--30),数值型
PRIVATE NL_Year,NL_Mmoth,NL_Day,天数,天数A,iii,i,sum,leap,sum_month,sum_day
IF obNL_year<1900 OR obNL_year>2049
MESSAGEBOX("年份出错,大小在1900--2049年之间",0+64,"农历年")
RETURN .F.
ENDIF
IF obNL_month<1 OR obNL_month>12
MESSAGEBOX("月份出错,大小在1--12月之间",0+64,"农历月")
RETURN .F.
ENDIF
IF obNL_day<1 OR obNL_day>30
MESSAGEBOX("日期出错,大小在1--30日之间",0+64,"农历日")
RETURN .F.
ENDIF
set cent on
set date to ymd
dime lunarInfo(150)&&月份信息
******二进制一共17位,第一个为判断是否为闰月为大月还是小月,大月30天,小月29天;
******2--13位为判断大小月;最后四位为判断闰几月
lunarInfo(1)=0x04bd8
lunarInfo(2)=0x04ae0
lunarInfo(3)=0x0a570
lunarInfo(4)=0x054d5
lunarInfo(5)=0x0d260
lunarInfo(6)=0x0d950
lunarInfo(7)=0x16554
lunarInfo(8)=0x056a0
lunarInfo(9)=0x09ad0
lunarInfo(10)=0x055d2
lunarInfo(11)=0x04ae0
lunarInfo(12)=0x0a5b6
lunarInfo(13)=0x0a4d0
lunarInfo(14)=0x0d250
lunarInfo(15)=0x1d255
lunarInfo(16)=0x0b540
lunarInfo(17)=0x0d6a0
lunarInfo(18)=0x0ada2
lunarInfo(19)=0x095b0
lunarInfo(20)=0x14977
lunarInfo(21)=0x04970
lunarInfo(22)=0x0a4b0
lunarInfo(23)=0x0b4b5
lunarInfo(24)=0x06a50
lunarInfo(25)=0x06d40
lunarInfo(26)=0x1ab54
lunarInfo(27)=0x02b60
lunarInfo(28)=0x09570
lunarInfo(29)=0x052f2
lunarInfo(30)=0x04970
lunarInfo(31)=0x06566
lunarInfo(32)=0x0d4a0
lunarInfo(33)=0x0ea50
lunarInfo(34)=0x06e95
lunarInfo(35)=0x05ad0
lunarInfo(36)=0x02b60
lunarInfo(37)=0x186e3
lunarInfo(38)=0x092e0
lunarInfo(39)=0x1c8d7
lunarInfo(40)=0x0c950
lunarInfo(41)=0x0d4a0
lunarInfo(42)=0x1d8a6
lunarInfo(43)=0x0b550
lunarInfo(44)=0x056a0
lunarInfo(45)=0x1a5b4
lunarInfo(46)=0x025d0
lunarInfo(47)=0x092d0
lunarInfo(48)=0x0d2b2
lunarInfo(49)=0x0a950
lunarInfo(50)=0x0b557
lunarInfo(51)=0x06ca0
lunarInfo(52)=0x0b550
lunarInfo(53)=0x15355
lunarInfo(54)=0x04da0
lunarInfo(55)=0x0a5d0
lunarInfo(56)=0x14573
lunarInfo(57)=0x052d0
lunarInfo(58)=0x0a9a8
lunarInfo(59)=0x0e950
lunarInfo(60)=0x06aa0
lunarInfo(61)=0x0aea6
lunarInfo(62)=0x0ab50
lunarInfo(63)=0x04b60
lunarInfo(64)=0x0aae4
lunarInfo(65)=0x0a570
lunarInfo(66)=0x05260
lunarInfo(67)=0x0f263
lunarInfo(68)=0x0d950
lunarInfo(69)=0x05b57
lunarInfo(70)=0x056a0
lunarInfo(71)=0x096d0
lunarInfo(72)=0x04dd5
lunarInfo(73)=0x04ad0
lunarInfo(74)=0x0a4d0
lunarInfo(75)=0x0d4d4
lunarInfo(76)=0x0d250
lunarInfo(77)=0x0d558
lunarInfo(78)=0x0b540
lunarInfo(79)=0x0b5a0
lunarInfo(80)=0x195a6
lunarInfo(81)=0x095b0
lunarInfo(82)=0x049b0
lunarInfo(83)=0x0a974
lunarInfo(84)=0x0a4b0
lunarInfo(85)=0x0b27a
lunarInfo(86)=0x06a50
lunarInfo(87)=0x06d40
lunarInfo(88)=0x0af46
lunarInfo(89)=0x0ab60
lunarInfo(90)=0x09570
lunarInfo(91)=0x04af5
lunarInfo(92)=0x04970
lunarInfo(93)=0x064b0
lunarInfo(94)=0x074a3
lunarInfo(95)=0x0ea50
lunarInfo(96)=0x06b58
lunarInfo(97)=0x055c0
lunarInfo(98)=0x0ab60
lunarInfo(99)=0x096d5
lunarInfo(100)=0x092e0
lunarInfo(101)=0x0c960
lunarInfo(102)=0x0d954
lunarInfo(103)=0x0d4a0
lunarInfo(104)=0x0da50
lunarInfo(105)=0x07552
lunarInfo(106)=0x056a0
lunarInfo(107)=0x0abb7
lunarInfo(108)=0x025d0
lunarInfo(109)=0x092d0
lunarInfo(110)=0x0cab5
lunarInfo(111)=0x0a950
lunarInfo(112)=0x0b4a0
lunarInfo(113)=0x0baa4
lunarInfo(114)=0x0ad50
lunarInfo(115)=0x055d9
lunarInfo(116)=0x04ba0
lunarInfo(117)=0x0a5b0
lunarInfo(118)=0x15176
lunarInfo(119)=0x052b0
lunarInfo(120)=0x0a930
lunarInfo(121)=0x07954
lunarInfo(122)=0x06aa0
lunarInfo(123)=0x0ad50
lunarInfo(124)=0x05b52
lunarInfo(125)=0x04b60
lunarInfo(126)=0x0a6e6
lunarInfo(127)=0x0a4e0
lunarInfo(128)=0x0d260
lunarInfo(129)=0x0ea65
lunarInfo(130)=0x0d530
lunarInfo(131)=0x05aa0
lunarInfo(132)=0x076a3
lunarInfo(133)=0x096d0
lunarInfo(134)=0x04bd7
lunarInfo(135)=0x04ad0
lunarInfo(136)=0x0a4d0
lunarInfo(137)=0x1d0b6
lunarInfo(138)=0x0d250
lunarInfo(139)=0x0d520
lunarInfo(140)=0x0dd45
lunarInfo(141)=0x0b5a0
lunarInfo(142)=0x056d0
lunarInfo(143)=0x055b2
lunarInfo(144)=0x049b0
lunarInfo(145)=0x0a577
lunarInfo(146)=0x0a4b0
lunarInfo(147)=0x0aa50
lunarInfo(148)=0x1b255
lunarInfo(149)=0x06d20
lunarInfo(150)=0x0ada0
*传回农历Y年及之前的总天数
baseDate={^1900-01-30}&&初始起算日期,1900-01-31即为春节(第一天)
天数=0
FOR iii=1 TO obNL_Year-1900 &&obNL_Year-1899-1,之前有多少年
天数A=0
i=0x8000
sum=348&&为一年的所有阴历月按29天/月计,12个月的天数,不考虑闰月
do while i>0x8&&传回有多少个大月,每个大月多加1天
    sum=sum+iif(bitand(lunarInfo(iii),i)<>0,1,0)&&大月传回1,小月传回0
    i=bitrshift(i,1)
enddo
leap=bitand(lunarInfo(iii),0xf)&&传回农历闰哪个月,没闰传回0
if leap<>0&&有闰月,传回闰月的天数
    s=iif(bitand(lunarInfo(iii),0x10000)<>0,30,29)
else
    s=0
endif
天数A=sum+s&&当年农历总天数
天数=天数+天数A &&累计总天数
ENDFOR
*************上面:天数 为在今年之前的所有农历年各总天数的和
i=0x8000
sum_month=0
FOR iii=1 TO obNL_month-1   &&传回当年之前几个月的总天数,大月30天,小月29天
    sum_month=sum_month+iif(bitand(lunarInfo(obNL_Year-1899),i)<>0,30,29)&&大月传回1,小月传回0
    i=bitrshift(i,1)
ENDFOR
天数=天数+sum_month &&累计总天数
**************上面:天数 为在今年之前的所有农历年各总天数的和+今年之前几个农历月的各总天数的和
天数=天数+obNL_day
sum_day=iif(bitand(lunarInfo(obNL_Year-1899),i)<>0,30,29) &&&当月总天数,用于判断农历日期是否正确
IF obNL_day>sum_day
MESSAGEBOX("日期出错,农历当年当月无此日,最多: "+ALLTRIM(STR(sum_day))+" 天,返回日期向后顺延!!",0+64,"农历日期")
ENDIF
RETURN {^1900-01-30}+天数

*FUNCTION NLTOYL
*函数调用格式: NLTOYL(年,月,日),参数值均为数值型
2010-02-12 21:36
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
http://www.

★★★★★为人民服务★★★★★
2010-02-16 17:28
w__w__w
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-12-13
收藏
得分:0 
阴历转农历???不明白。
2012-03-05 13:19
快速回复:求助:在网上看到TC程序的阴历转农历程,求高手改编VFP中用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060246 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved