纯python中文日历库
lunardate的Python项目详细描述
中国历法:http://en.wikipedia.org/wiki/Chinese_calendar
用法
>>> LunarDate.fromSolarDate(1976, 10, 1) LunarDate(1976, 8, 8, 1) >>> LunarDate(1976, 8, 8, 1).toSolarDate() datetime.date(1976, 10, 1) >>> LunarDate(1976, 8, 8, 1).year 1976 >>> LunarDate(1976, 8, 8, 1).month 8 >>> LunarDate(1976, 8, 8, 1).day 8 >>> LunarDate(1976, 8, 8, 1).isLeapMonth True>>> today = LunarDate.today() >>> type(today).__name__ 'LunarDate'>>> # support '+' and '-' between datetime.date and datetime.timedelta >>> ld = LunarDate(1976,8,8) >>> sd = datetime.date(2008,1,1) >>> td = datetime.timedelta(days=10) >>> ld-ld datetime.timedelta(0) >>> (ld-sd).days -11444 >>> ld-td LunarDate(1976, 7, 27, 0) >>> (sd-ld).days 11444 >>> ld+td LunarDate(1976, 8, 18, 0) >>> td+ld LunarDate(1976, 8, 18, 0) >>> ld2 = LunarDate.today() >>> ld < ld2 True >>> ld <= ld2 True >>> ld > ld2 False >>> ld >= ld2 False >>> ld == ld2 False >>> ld != ld2 True >>> ld == ld True >>> LunarDate.today() == LunarDate.today() True >>> before_leap_month = LunarDate.fromSolarDate(2088, 5, 17) >>> before_leap_month.year 2088 >>> before_leap_month.month 4 >>> before_leap_month.day 27 >>> before_leap_month.isLeapMonth False >>> leap_month = LunarDate.fromSolarDate(2088, 6, 17) >>> leap_month.year 2088 >>> leap_month.month 4 >>> leap_month.day 28 >>> leap_month.isLeapMonth True >>> after_leap_month = LunarDate.fromSolarDate(2088, 7, 17) >>> after_leap_month.year 2088 >>> after_leap_month.month 5 >>> after_leap_month.day 29 >>> after_leap_month.isLeapMonth False
限制
这个图书馆只能处理1900年至2099年(中国历法)。
另请参见
- 月球:http://packages.qa.debian.org/l/lunar.html, 一种用C语言编写的转换器,这个程序就是从它派生出来的。
- Python月相:http://code.google.com/p/liblunar/ 另一个用c编写的库,包括python绑定。