纯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年(中国历法)。

另请参见

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何向第二个组合框模型项添加数组值从第一个组合框所选项获取数组名称?   使用Java与WebSphere的SSL握手错误   eclipse线程“main”Java中的第一个Java程序异常。lang.NoClassDefFoundError   java将Javafx应用作为Web应用移植的最佳方式   IDE的java右JVM文件夹   java如何在基本适配器中停止文本到语音   java If block使用substring和equals方法以假值执行   在本例中,如何在java中返回多个值?   java第二个主类在maven构建期间覆盖第一个主类   如何在java中设置运行时ArrayList的泛型类型?   java从主机读取文件