C 公曆轉農曆演算法

2021-09-30 04:23:57 字數 1905 閱讀 8971

using system;

using system.collections.generic;

using system.text;

//地支

private static string dizhi = ;

//十二生肖

private static string shengxiao = ;

//農曆日期

private static string dayname =   ;

//農曆月份

private static string monthname = ;

private static string weekday = ;

//公曆月計數天

private static int monthadd = ;

//農曆資料

private static int lunardata = ;

///

/// 獲取對應日期的農曆

///

/// 公曆日期

///

public string getlunarcalendar(datetime dtday)

catch

int nthedate;

int nisend;

int k, m, n, nbit, i;

string calendar = string.empty;

//計算到初始時間2023年2月8日的天數:1921-2-8(正月初一)

nthedate = (year - 1921) * 365 + (year - 1921) / 4 + day + monthadd[month - 1] - 38;

if ((year % 4 == 0) && (month > 2))

nthedate += 1;

//計算天乾,地支,月,日

nisend = 0;

m = 0;

k = 0;

n = 0;

while (nisend != 1)

nthedate = nthedate - 29 - nbit;

n = n - 1;

}if (nisend == 1)

break;

m = m + 1;

}year = 1921 + m;

month = k - n + 1;

day = nthedate;

//return year+"-"+month+"-"+day;

#region 格式化日期顯示為三月廿四

if (k == 12)

//生肖

calendar = shengxiao[(year - 4) % 60 % 12].tostring() + "年 ";

//天乾

calendar += tiangan[(year - 4) % 60 % 10].tostring();

//地支

calendar += dizhi[(year - 4) % 60 % 12].tostring() + " ";

//農曆月

if (month < 1)

calendar += "閏" + monthname[-1 * month].tostring() + "月";

else

calendar += monthname[month].tostring() + "月";

//農曆日

calendar += dayname[day].tostring() + "日";

#endregion

//計算星期

string week="星期"+weekday[(int)dtday.dayofweek];

calendar +=" "+ week;

return calendar;}}

}

公曆轉農曆

public string chineselunisolardate datetime adatatime 年月 甲乙丙丁戊己庚辛壬癸 year 4 10 子丑寅卯辰巳午未申酉戌亥 year 4 12 鼠牛虎兔龍蛇馬羊猴雞狗豬 year 4 12 month leapmonth 潤 無正二三四五六七...

c 版公曆轉農曆

using system namespace ljtools private static int year20 new int private static int year19 new int private static int year2000 new int private static ...

公曆轉農曆函式

庫名 gton.h 程式by gshuang1 ifndef gton h 防止過載 define gton h uchar idata datenong 4 uchar code data1 公曆各個月的天數 uchar code days in a mon 2 12 uchar yearstyp...