Python3 公曆轉農曆

2021-10-21 12:54:38 字數 1297 閱讀 8321

#!/user/bin/env python3

# -*- coding: utf-8 -*-

import sxtwl

lunar = sxtwl.lunar(

)#例項化日曆庫

print

(lunar)

ymc =

[u"十一"

, u"十二"

, u"正"

, u"二"

, u"三"

, u"四"

, u"五"

, u"六"

, u"七"

, u"八"

, u"九"

, u"十"

]rmc =

[u"初一"

, u"初二"

, u"初三"

, u"初四"

, u"初五"

, u"初六"

, u"初七"

, u"初八"

, u"初九"

, u"初十"

, u"十一"

, u"十二"

, u"十三"

, u"十四"

, u"十五"

, u"十六"

, u"十七"

, u"十八"

, u"十九"

, u"二十"

, u"廿一"

, u"廿二"

, u"廿三"

, u"廿四"

, u"廿五"

, u"廿六"

, u"廿七"

, u"廿八"

, u"廿九"

, u"三十"

, u"卅一"

]day = lunar.getdaybysolar(

2021,3

,9)#通過陽曆獲取查詢日期資訊

print

(u"公曆:"

, day.y, u"年"

, day.m, u"月"

, day.d, u"日"

)if day.lleap:

print

(u"陰曆:潤"

, ymc[day.lmc]

, u"月"

, rmc[day.ldi]

, u"日"

)else

:print

(u"陰曆:"

, ymc[day.lmc]

, u"月"

, rmc[day.ldi]

, u"日"

)

參考

1.2.python下的乙個好用的日曆庫,支援農曆轉公曆,和公曆轉農曆等功能

公曆轉農曆

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

公曆轉農曆函式

庫名 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...

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 ...