pyUnit_calendar
这是一个阳历转化农历的程序(注意该模块严重依赖时间,所以系统中的时间和时区必须是:中国北京时间和中国时区)
介绍
Python版阳历转农历
安装
pip install pyunit-calendar
如果阳历和农历相互转换推荐使用
from pyunit_calendar import LunarDate,LunarSolarDateConverter,SolarDate
if __name__ == "__main__":
"""测试简单快速的农历和阳历互转"""
converter = LunarSolarDateConverter()
lunar = converter.solar_to_lunar(SolarDate(2019, 12, 6))
print(lunar)
solar = converter.lunar_to_solar(LunarDate(2019, 11, 10))
print(solar)
如果只有阳历转农历推荐使用
from pyunit_calendar import SC
if __name__ == "__main__":
lun = SC(year=2018, month=1, day=2)
print(lun.y)
print(lun.year)
print(lun.m)
print(lun.month)
print(lun.d)
print(lun.day)
print(lun.w)
print(lun.week)
print(lun.h)
print(lun)
如果只有农历转阳历推荐使用
from pyunit_calendar import CTC
if __name__ == "__main__":
c = CTC(ctc_year=2017, ctc_mon=-6, ctc_day=8)
print(c.find_sc())
print(c.get_year())
print(c.get_month())
print(c.get_day())
天干地支转日历(转阳历和农历)
from pyunit_calendar import BatchCalendar
if __name__ == "__main__":
bc=BatchCalendar()
print("-----------------------------")
print(bc.ctc_to_sc("1984年闰十月初三"))
print(bc.ctc_to_td("1984年闰十月初三"))
print("-----------------------------")
print(bc.sc_to_ctc("1984年11月25日"))
print(bc.sc_to_td("1984年11月25日"))
print("-----------------------------")
print(bc.td_to_ctc("甲子年乙亥月癸亥日"))
print(bc.td_to_sc("甲子年乙亥月癸亥日"))
Docker安装(注意该模块严重依赖时间,所以系统中的时间和时区必须是:中国北京时间和中国时区)
docker pull pyunit-calendar
docker run -P -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime -d pyunit-calendar
农历转阳历
参数名 | 类型 | 是否可以为空 | 说明 |
---|
year | int | YES | 输入阿拉伯数字的年 |
month | int | YES | 输入阿拉伯数字的月(如果是闰月前面添加负号:如-4表示闰4月) |
day | int | YES | 输入阿拉伯数字的日 |
请求示例
Python3 Requests测试
import requests
url = "http://127.0.0.1:32768/pyunit/calendar/LunarCalendar"
data = {
"year": 2020,
"month": -4,
"day": 11
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=data, headers=headers).json()
print(response)
返回结果
{
"code": 200,
"result": {
"date": "2020年6月2日",
"day": "2",
"month": "6",
"year": "2020"
}
}
阳历转农历
参数名 | 类型 | 是否可以为空 | 说明 |
---|
year | int | YES | 输入阿拉伯数字的年 |
month | int | YES | 输入阿拉伯数字的月 |
day | int | YES | 输入阿拉伯数字的日 |
请求示例
Python3 Requests测试
import requests
url = "http://127.0.0.1:32768/pyunit/calendar/SolarCalendar"
data = {
"year": 2020,
"month": 6,
"day": 2
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=data, headers=headers).json()
print(response)
返回结果
{
"code": 200,
"result": {
"date": "二零二零年 闰四月 十一 星期二 节日:无",
"day": "十一",
"holiday": "无",
"is_leap": "是",
"month": "闰四",
"week": "星期二",
"year": "二零二零"
}
}
天干地支和农历和阳历相互转日期
参数名 | 类型 | 是否可以为空 | 说明 |
---|
date | string | YES | 输入当前的日期:可以输入三种格式,具体看请求示例 |
请求示例
Python3 Requests测试
import requests
url = "http://127.0.0.1:32768/pyunit/calendar/BatchCalendar"
data = {
"date": '2020年四月十一',
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=data, headers=headers).json()
print(response)
返回结果
{
"code": 200,
"result": {
"HSTTB": "庚子年庚辰月丙午日",
"LunarCalendar": "2020年四月十一",
"SolarCalendar": "2020年05月03日"
}
}