@muguilin/calendar
v1.0.1
Published
calendar.js, JavaScript日历插件, JavaScript日历转换库
Downloads
6
Maintainers
Readme
calendar - JavaScript 日历插件、日历转换库
JavaScript 日历插件、日历转换库
中国农历(阴阳历)和西元阳历即公历互转JavaScript库 js-calendar-converter
下载安装:
# 使用npm命令下载安装
$ npm i @muguilin/calendar
# 使用yarn命令下载安装
$ yarn add @muguilin/calendar
使用实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript 日历、转换库</title>
<style>
body { padding: 50px; }
section { margin: 50px auto; width: 1200px; }
h1{ text-align: center; }
#el { margin: auto; padding: 20px; width: 500px; height: 310px; border: 1px solid gray; overflow: auto;}
#el table{ width: 100%; text-align: center; }
.now{ background-color: blue; color: #fff; }
button { font-size: 16px; }
</style>
</head>
<body>
<h1>JavaScript 日历、转换库</h1>
<hr />
<section>
<h1 id="toDay"></h1>
<main>
<!--<button type="button" id="perv">上一月</button>
<button type="button" id="next">下一月</button>-->
<div id="calendar"> </div>
</main>
</section>
<script type="module">
import { muCalendar, solar2lunar, lunar2solar } from '@muguilin/calendar';
// 日历
{
const calendar = muCalendar(document.querySelector('#calendar'));
console.log(calendar);
}
// 转换
{
console.log('公历年月日转农历数据:', solar2lunar());
const {Animal, gzYear, cYear, cMonth, cDay, ncWeek, IMonthCn, IDayCn} = solar2lunar();
console.log('农历年月日转公历年月日:', lunar2solar(cYear, cMonth, cDay));
toDay.innerHTML = `${Animal}【${gzYear}】,国历:${cYear}年${cMonth}月${cDay}日 ${ncWeek} ,农历:${IMonthCn} ${IDayCn}`
};
</script>
</body>
</html>