求PB公历转农历的函数
求PB公历转农历的函数,已经搜过几个,但好像用不了啊。http://topic.csdn.net/u/20081111/09/1D04FA30-D94C-4F9E-AA24-18A9AAA547F1.html
[解决办法]
原来在网上捡的.另存一个 .srf 文件导入PBL 成一个全局函数即可.
- C/C++ code
$PBExportHeader$of_day_to_lunar.srf$PBExportComments$将公历转换为农历global type of_day_to_lunar from function_objectend typeforward prototypesglobal function string of_day_to_lunar (date ad_date)end prototypesglobal function string of_day_to_lunar (date ad_date);/*********************************************************************函数名称: of_day_to_lunar传递参数: date ad_date; - 传入农历日期 返回参数: STRING********************************************************************功能描述: 计算农历:传入公历计算农历********************************************************************备注: *********************************************************************/string ls_retlong lunarinfo[151] = { &19416, 19168, 42352, 21717, 53856, 55632, 91476, 22176, 39632, 21970, &19168, 42422, 42192, 53840,119381, 46400, 54944, 44450, 38320, 84343, &18800, 42160, 46261, 27216, 27968,109396, 11104, 38256, 21234, 18800, &25958, 54432, 59984, 28309, 23248, 11104,100067, 37600,116951, 51536, &54432,120998, 46416, 22176,107956, 9680, 37584, 53938, 43344, 46423, &27808, 46416, 86869, 19872, 42448, 83315, 21200, 43432, 59728, 27296, &44710, 43856, 19296, 43748, 42352, 21088, 62051, 55632, 23383, 22176, &38608, 19925, 19152, 42192, 54484, 53840, 54616, 46400, 46496,103846, &38320, 18864, 43380, 42160, 45690, 27216, 27968, 44870, 43872, 38256, &19189, 18800, 25776, 29859, 59984, 27480, 21952, 43872, 38613, 37600, &51552, 55636, 54432, 55888, 30034, 22176, 43959, 9680, 37584, 51893, &43344, 46240, 47780, 44368, 21977, 19360, 42416, 86390, 21168, 43312, &31060, 27296, 44368, 23378, 19296, 42726, 42208, 53856, 60005, 54576, &23200, 30371, 38608, 19415, 19152, 42192,118966, 53840, 54560, 56645, &46496, 22224, 21938, 18864, 42359, 42160, 43600,111189, 27936, 44448, &84835 }//公历每月的天数long SolarMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}//干string Gan[10] = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}//支string Zhi[12] = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}//生肖string Animals[12] = {"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}//24节气string SolarTerm[24] = {"小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", & "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"}//24节气的时间,以分来计long sTermInfo[24] = {0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, & 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758}string nStr1[11] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}string nStr2[5] = {"初", "十", "廿", "卅", " "}string MonthName[12] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}long ll_year,ll_mon,ll_daylong ll_lyear,ll_lmon,ll_lday//年,月,日ll_year = year(ad_date)ll_mon = month(ad_date)ll_day = day(ad_date)double ld_numlong ll_leap,ll_sumday,ll_leapdayslong ll_info,k,ilong ll_temp,ll_offsetboolean lb_isleapstring ls_bin,ls_codell_leap = 0ll_temp = 0//计算与1900-1-30 (农历1-1)的天数ll_offset = daysafter(date("1900-1-30"),ad_date) //计算农历 for i = 1900 to 2050 //求当年农历年的天数 ll_sumday = 348 //12个小月,每月29 k = 32768 //0x8000 ll_info = lunarinfo[i - 1900 + 1] ls_bin = of_dectobin_fixlen(ll_info,16) for k = 1 to 12 ll_sumday = ll_sumday + integer(left(right(ls_bin,k + 4),1)) next //计算农历年闰月的天数 //计算闰月的月份 ll_leap = of_bitand(ll_info,15) //与0xF进行与操作,得到最后一位 if ll_leap > 0 then //有闰月,0为无闰月 ll_temp = of_bitand(ll_info, 65536) //与0x10000进行与操作 if ll_temp = 0 then //得到闰月天数 ll_leapdays = 29 else ll_leapdays = 30 end if else ll_leapdays = 0 end if //农历全年天数 ll_sumday = ll_sumday + ll_leapdays ll_offset = ll_offset - ll_sumday if ll_offset < 1 then exitnextll_offset = ll_offset + ll_sumday//农历年ll_lyear = ilb_isleap = falsefor i = 1 to 12 if ll_leap > 0 and i = ll_leap + 1 and lb_isleap = false then //闰月 lb_isleap = true i = i - 1 //闰月的天数 ll_temp = ll_leapdays else //计算非闰月的天数:ll_lyear年i月的总天数 k = 65536 //0x10000 //对k进行二进制右移移i位操作 ls_bin = of_dectobin(k) //转换成二进制字符串 ls_code = mid(ls_bin,1,len(ls_bin) - i) //右移i位 k = of_bintodec(ls_code) //转换成十进制 if of_bitand(ll_info,k) > 0 then //得到大小月 ll_temp = 30 else ll_temp = 29 end if end if ll_offset = ll_offset - ll_temp if ll_offset < 0 then exit nextll_offset = ll_offset + ll_temp//农历月ll_lmon = i
[解决办法]
采用dll实现,如果需要可以发至邮箱