摘要:Chinese Zodiac Selector (出生日期轉換為天干地支及生肖)
非常簡單但是要用又找不到,自己寫一個(程式沒有將日期轉換為農曆,所以請勿直接拿去用,會有例外的錯誤判斷).
![](http://www.dotblogs.com.tw/Providers/BlogEntryEditor/FCKeditor/editor/dialog/InsertCode/codeimages/None.gif)
BOOL GetChiZodiac(
int nYear,
char* pcChiZodic)
![](http://www.dotblogs.com.tw/Providers/BlogEntryEditor/FCKeditor/editor/dialog/InsertCode/codeimages/ExpandedBlockStart.gif)
...{
char* ppcTianGan[] = ...{ "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
char* ppcDiZhi[] = ...{ "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
char* ppcChiZodic[] = ...{ "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "豬" };
int nJia, nTianGan, nDiZhi;
nJia = (nYear - 3) % 60 - 1;
nJia += 60;
nTianGan = nJia % 10;
nDiZhi = nJia % 12;
strcpy(pcChiZodic, ppcChiZodic[nDiZhi]);
printf("天干: %s 地支: %s 生肖: %s\n", ppcTianGan[nTianGan], ppcDiZhi[nDiZhi], ppcChiZodic[nDiZhi]);
return TRUE;
} 參考公式:天干地支.rar
國曆農曆轉換請參考此篇
![勤勞樸實](http://www.januarytc.com/cj/img/myword.gif)