jjonline / calendar.js Goto Github PK
View Code? Open in Web Editor NEW**农历(阴阳历)和西元阳历即公历互转JavaScript库
License: GNU General Public License v3.0
**农历(阴阳历)和西元阳历即公历互转JavaScript库
License: GNU General Public License v3.0
阳历1995-06-17转换到阴历变成1995-06-20,实际应该是1995-05-20,月份多了1
还有为什么有时候转换,时辰也会变化?
求大佬支援
本来想自己加的,结果看了网上的推算方法,一头雾水!!实在看不懂历法!
有当天的宜忌就可以,时辰的太细,没必要!看了一些源码,固定的数据很少,只是搞不懂规则怎么取到对的。。。。。
剛找到這,看著有點感概。
2014年尾的時候,我在網上找新舊歷轉換,找到一些網頁有你2014年中的舊版本,我放到在我的project裡面來用。
之後的日子也遇到過一些人跟我說我的project日期轉換有bug之類的,我也在我copy的版本裡fix過。
最近我剛想著把那project重構,又在看看calendar轉換,就找到你這裡了。
這樣子就8年光陰了。人生匆匆,沒有幾多個8年,藉著代碼在人海裡遇上過又再遇上,也是緣份吧。
有看到你blog最近的一篇,疫情年不好過吧。默默的想跟你說句加油吧。
大佬!现在的时间转农历不对啊
即时辰的转换~~~
C:\Users\25166\Desktop\vue\fullcalendar-example-projects\vue-vuex\src\assets\calendar.js
417:13 error Unreachable code no-unreachable
420:13 error Unreachable code no-unreachable
462:17 error 'objDate' is already defined no-redeclare
466:13 error 'y' is already defined no-redeclare
467:13 error 'm' is already defined no-redeclare
468:13 error 'd' is already defined no-redeclare
493:13 error 'leap' is already defined no-redeclare
608:13 error 'isLeapMonth' is already defined no-redeclare
609:13 error 'leapOffset' is assigned a value but never used no-unused-vars
611:13 error 'leapDay' is assigned a value but never used no-unused-vars
629:17 error 'i' is already defined no-redeclare
最近做中医的项目,有这个需要
今天阳历是2021年12月14日,计算的结果是农历IDayCn: "初十" IMonthCn: "十月" 今天农历是 十一月十一
能讲解下原理吗?
因为你每次都要从1900年叠加起
重复点击tab栏,日期会发生变化,重复点击tab栏的阴历或者阳历,日期会一直变化,请问怎么解决?
哈喽,作者大佬你好。
我在使用您的插件中发现阳历1996-10-1对应的农历应该是八月十九,但是插件的计算结果是八月二十
1996这年的0x055c0应该是0x05ac0
1933年7月22日 是 闰五月三十。
大佬,我想显示每天是周几能在这个基础扩展吗?期待你的回复,万分感谢
看了源码才发现传入的月份为1-12(含12),即自然月表示法.
然而,js原生的Date()对象的月份是0-11(含11)即自然月-1.既然js标准我们改变不了,那为什么不去适应它呢.这边调用函数month+1,传入参数再month-1图个啥呢.很多时候就直接传参了,导致非常复杂的bug改起来那叫一个酸爽.
1、阴历农历的转换为基础库js
2、节气与星座等,分别独立成js文件
3、通过简单脚本可以合并所有的,也可以按需索取
好处:减少文本容量
建议生成一个NPM包,这样大家都能用到统一最新的包
小程序怎么使用这个js,直接使用报错。
如题
初次使用这个插件,没有作任何修改,发现有以下两个问题:1、每月最后一天和下个月的第一天,比如31号跟1号,显示出的农历信息重复
2、获取到的节气是错误的
如图:
我以为是我传参问题,但是不论我怎么修改,都无法正确的显示相应信息。后查看源码,发现部分逻辑存在错误之处,已经在pr中做修改#25。
以上修改都经过验证,已经能拿到正确信息。第一次提pr,不太懂操作,如果pr代码中或者提交操作上有不妥之处,望指出,我会及时更改。
Lines 505 to 530 in 0c968ed
var _24 = calendar.getTerm(1987,3) ; // _24=4;意即1987年2月4日立春
想问下 2 月是怎么得到的
2020-07-13 对应的农历是闰月,返回的结果并不是闰月
本来节气 只有在节气当天显示, 不在当天的时候,节气是null。
按照历法,节气,只是这一段时间的天气,所以讲节气显示出来。
并且取出了下一个节气及其日期。
修改1:
修改2:
`
//传入的日期的节气与否
let isTerm = false;
let Term = null;
let nextTerm = null;
let nextTermDate = null;
if (d == firstNode || d == secondNode) {
isTerm = true
}
if (d < firstNode){
Term = this.solarTerm[(m*2-3)>=0?m*2-3:23];
nextTerm = this.solarTerm[m*2-2];
nextTermDate = y + '-' + m + '-' + firstNode
}
if (d >= firstNode && d < secondNode) {
Term = this.solarTerm[m*2 - 2];
nextTerm = this.solarTerm[m*2 - 1];
nextTermDate = y + '-' + m + '-' + secondNode
}
if (d >= secondNode) {
Term = this.solarTerm[m*2 - 1];
if (m == 12) {
nextTerm = this.solarTerm[0];
nextTermDate = (y+1) + '-' + 1 + '-' + this.getTerm(y+1, 1)
} else {
nextTerm = this.solarTerm[m*2];
nextTermDate = y + '-' + (m+1) + '-' + this.getTerm(y, ((m+1) * 2 - 1))
}
}
//日柱 当月一日与 1900/1/1 相差天数
const dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10;
const gzD = this.toGanZhi(dayCyclical + d - 1);
//该日期所属的星座
const astro = this.toAstro(m, d);
const solarDate = y + '-' + m + '-' + d;
const lunarDate = year + '-' + month + '-' + day;
const festival = this.festival;
const lFestival = this.lFestival;
const festivalDate = m + '-' + d;
let lunarFestivalDate = month + '-' + day;
// bugfix https://github.com/jjonline/calendar.js/issues/29
// 农历节日修正:农历12月小月则29号除夕,大月则30号除夕
// 此处取巧修正:当前为农历12月29号时增加一次判断并且把lunarFestivalDate设置为12-30以正确取得除夕
// 天朝农历节日遇闰月过前不过后的原则,此处取农历12月天数不考虑闰月
// 农历润12月在本工具支持的200年区间内仅1574年出现
if (month === 12 && day === 29 && this.monthDays(year, month) === 29) {
lunarFestivalDate = '12-30';
}
return {
date: solarDate,
lunarDate: lunarDate,
festival: festival[festivalDate] ? festival[festivalDate].title : null,
lunarFestival: lFestival[lunarFestivalDate] ? lFestival[lunarFestivalDate].title : null,
'lYear': year,
'lMonth': month,
'lDay': day,
'Animal': this.getAnimal(year),
'IMonthCn': (isLeap ? "\u95f0" : '') + this.toChinaMonth(month),
'IDayCn': this.toChinaDay(day),
'cYear': y,
'cMonth': m,
'cDay': d,
'gzYear': gzY,
'gzMonth': gzM,
'gzDay': gzD,
'isToday': isToday,
'isLeap': isLeap,
'nWeek': nWeek,
'ncWeek': "\u661f\u671f" + cWeek,
'isTerm': isTerm,
'Term': Term,
'nextTerm':nextTerm,
'nextTermDate':nextTermDate,
'astro': astro
};`
如题
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.