一款支持星座、干支、生肖、节气、节日、彭祖百忌、每日宜忌等超卷的日历工具库

大家好,我是凌览。

日常GitHub划水发现一款超级6的日历工具库lunar,它支持阳历、阴历、佛历和道历,甚至还玩上了星座、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。大多数日历需求使用它都能满足。

lunar还提供了多种开发语言支持,包括有:javascript、java、.net、php、python、go、typescript、flutter、swift。

示例

我们来看看它给出的示例。

  • 年历
  • 仿百度搜索月历
  • 月历
  • 农历月历
  • 周历
  • 老黄历

快速上手

这里演示lunar的javascript版。 安装:

js 复制代码
npm install lunar-javascript

使用:

js 复制代码
const {Solar, Lunar, HolidayUtil} = require('lunar-javascript')
console.log(Lunar.fromDate(new Date()).toFullString())
console.log(Solar.fromYmd(2016, 1, 1).toFullString())
console.log(HolidayUtil.getHoliday(2020, 5, 2) + '')

lunar仅提供了API,并没有提供现成直接用的日历组件。 比如,阳历获取年月日、儒略日、星期、是否闰年、节日、星座、日期推移、日期相减、日期比较、薪资比例、转阴历。

js 复制代码
const {Solar} = require('lunar-javascript')

//获取年、月、日
var d = Solar.fromDate(new Date());
console.log(d.getYear());
console.log(d.getMonth());
console.log(d.getDay());

//儒略日
var d = Solar.fromDate(new Date());
console.log(d.getJulianDay());

//获取星期
var d = Solar.fromDate(new Date());
console.log(d.getWeek());//数字
console.log(d.getWeekInChinese());//中文

//是否闰年
var d = Solar.fromDate(new Date());
console.log(d.isLeapYear());

//....

比如,阴历获取年月日、获取时辰、获取星期、节日、干支、禄、生肖、节气、物候、数九、三伏、 二十八星宿、八卦方位、吉神方位等等。

js 复制代码
const {Lunar} = require('lunar-javascript')

//每日宜忌
var d = Lunar.fromDate(new Date());
// 宜var l = d.getDayYi();
for (var i=0, j=l.length; i<j; i++){
  console.log(l[i]);
}
// 忌
l = d.getDayJi();
for (var i=0, j=l.length; i<j; i++){
  console.log(l[i]);
}

阴历五花八门的,此处不再列举更多视自身需求选择。

工具文档地址:6tail.cn/calendar/ap...

(完)

关注公粽号【程序员凌览】回复"666",拉您进【人类高质量前端交流群~】

往期推荐:linglan01.cn/about

相关推荐
●VON2 分钟前
React Native for OpenHarmony:项目目录结构与跨平台构建流程详解
javascript·学习·react native·react.js·架构·跨平台·von
We་ct12 分钟前
LeetCode 36. 有效的数独:Set实现哈希表最优解
前端·算法·leetcode·typescript·散列表
爱吃大芒果19 分钟前
Flutter for OpenHarmony 实战:mango_shop 路由系统的配置与页面跳转逻辑
开发语言·javascript·flutter
qq_1777673723 分钟前
React Native鸿蒙跨平台实现消息列表用于存储所有消息数据,筛选状态用于控制消息筛选结果
javascript·react native·react.js·ecmascript·harmonyos
weixin_3954489124 分钟前
main.c_cursor_0129
前端·网络·算法
RANCE_atttackkk25 分钟前
Springboot+langchain4j的RAG检索增强生成
java·开发语言·spring boot·后端·spring·ai·ai编程
沐雪架构师36 分钟前
LangChain 1.0 Agent开发实战指南
开发语言·javascript·langchain
2501_940007891 小时前
Flutter for OpenHarmony三国杀攻略App实战 - 战绩记录功能实现
开发语言·javascript·flutter
摘星编程1 小时前
React Native + OpenHarmony:自定义useEllipsis省略号处理
javascript·react native·react.js
2401_859049081 小时前
git submodule update --init --recursive无法拉取解决
前端·chrome·git