banner
biuaxia

biuaxia

"万物皆有裂痕,那是光进来的地方。"
github
bilibili
tg_channel

前端获取指定日期万年历

引入下方的 js 内容,调用 lunar(Date对象) 可以获得包含万年历信息的对象,js 文件来源自 360 万年历

完整文件下载:lunar.zip

效果图#

效果图.png

调用示例#

<!DOCTYPE html>
<html lang="zh-CN">
  <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>Document</title>
    <script src="./lunar.js"></script>
  </head>
  <body>
    <p id="out"></p>
    <script>
      var lunar = lunar(new Date());
      console.log("lunar: ", lunar);
      document.getElementById(
        "out"
      ).innerHTML = `${lunar.oDate.getFullYear()}年${(
        "0" +
        (lunar.oDate.getMonth() + 1)
      ).slice(-2)}月${("0" + lunar.oDate.getDate()).slice(-2)}日 星期${
        lunar.cnDay
      }<br/>农历${lunar.lMonth}月${lunar.lDate}<br/>${lunar.gzYear}年${
        lunar.gzMonth
      }月${lunar.gzDate}日<br/>[${lunar.animal}年]`;
    </script>
  </body>
</html>

参考资料#

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。