C++:公历转农历的程序

一、简介

        该算法从网上找到,将公历转成农历,只能计算1921年-2021年间的农历。只能显示 甲午年,生肖和农历,无法得到 庚午月、癸丑日。

 

二、函数

 

 

void Window::get_chinese_calendar(QDate english_calendar, QString &outLunarDay, QString &outLunarYear)
{
    int currentYear = 0, currentMonth = 0, currentDay = 0;
    int nTheDate = 0;
    int nisEnd = 0, flag = 0, n = 0, k = 0, nBit = 0, i = 0;
    char m_Lunar[100] = {0}, m_LunarDay[50] = {0}, m_zodiak[50] = {0};
   
    const char *m_TianGan[] = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
   
    const char *m_DiZhi[] = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
   
    const char *m_ShuXiang[] = {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
   
    const char *m_DayName[] = {"*","初一","初二","初三","初四","初五",
          "初六","初七","初八","初九","初十",
          "十一","十二","十三","十四","十五",
          "十六","十七","十八","十九","二十",
          "廿一","廿二","廿三","廿四","廿五",
          "廿六","廿七","廿八","廿九","三十"};
    
    const char *m_MonthName[] = {"*","正","二","三","四","五","六","七","八","九","十","十一","腊"};
   
    const int m_DayAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
   
    const int m_LunarData[100]= {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
                                 ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
                                 ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
                                 ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
                                 ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
                          

你可能感兴趣的:(C/C++)