Skip to main content

A pachage to convert Chinese Lunar Calendar to datetime

Project description

ZhDate 中国农历日期处理对象

VersionBadge pythonversion LicenseBadge

不用网络接口直接本地计算中国农历,支持农历阳历互转

感谢

EillesWan

更新

  • 修正农历初一前一天错误
  • 修正 f 字符串输出方式

安装方法

通过 pip 直接安装

pip install zh-lunar-date

或从 git 拉取

git clone https://github.com/chen-kay/zhdate.git
cd zhdate
python setup.py install

更新

pip install zh-lunar-date --upgrade

使用方法

见如下代码案例:

from zhdate import ZhDate

date1 = ZhDate(2010, 1, 1) # 新建农历 2010年正月初一 的日期对象
print(date1)  # 直接返回农历日期字符串
dt_date1 = date1.to_datetime() # 农历转换成阳历日期 datetime 类型

dt_date2 = datetime(2010, 2, 6)
date2 = ZhDate.from_datetime(dt_date2) # 从阳历日期转换成农历日期对象

date3 = ZhDate(2020, 4, 30, leap_month=True) # 新建农历 2020年闰4月30日
print(date3.to_datetime())

# 支持比较
if ZhDate(2019, 1, 1) == ZhDate.from_datetime(datetime(2019, 2, 5)):
    pass

# 减法支持
new_zhdate = ZhDate(2019, 1, 1) - 30  #减整数,得到差额天数的新农历对象
new_zhdate2 = ZhDate(2019, 1, 1) - ZhDate(2018, 1, 1) #两个zhdate对象相减得到两个农历日期的差额
new_zhdate3 = ZhDate(2019, 1, 1) - datetime(2019, 1, 1) # 减去阳历日期,得到农历日期和阳历日期之间的天数差额

# 加法支持
new_zhdate4 = ZhDate(2019, 1, 1) + 30 # 加整数返回相隔天数以后的新农历对象

# 中文输出
new_zhdate5 = ZhDate(2019, 1, 1)
print(new_zhdate5.chinese())

# 当天的农历日期
ZhDate.today()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zh_lunar_date-0.0.3-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file zh_lunar_date-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: zh_lunar_date-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for zh_lunar_date-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c968dbac47fd79d04fc33501bf66b774a21edb860574d8887de5881995262ffd
MD5 a90d5ab5ce0d86d02a5514af67b2c13b
BLAKE2b-256 514501391494b94b6bcde7b62af1bada2e6df1647cfbda3bd39a37fdf00b7d30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page