纯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:字符串。RTL设备语言用标志“+”格式化,数字后加符号   java GAE作为桌面应用程序(Swing)的服务提供商   java将InputStream转换为FileInputStream不适用于Apache POI   java外部Voronoi库“网格”:什么是草图和处理?   重载重写的泛型方法java   java显示组织上设置的错误。springframework。验证。jsp中的错误对象   java一些Spring模型属性没有显示在我的JSP中   java无法编译Guava 23的SimpleTimeLimiter示例   java如何更改JTree中的“根”目录名?   java如何在安卓中对相对布局产生连锁反应?   java错误:org。冬眠例外SQLGrammarException:无法提取结果集,dateAccessed是未知列   如何使用java监听JSON文件更新   由抽象封闭类创建的匿名内部类能否通过反射确定实现类?