在Vue项目中获取当前日期的农历(阴历)

在Vue项目中获取当前日期的农历(阴历)

chinese-lunar-calendar

npm安装

npm install –save chinese-lunar-calendar

在vue中的使用

<script>
import { getLunar } from 'chinese-lunar-calendar'
export default {
  data() {
    return {
  getLunarDay'',
  yearnew Date().getFullYear(),
       monthnew Date().getMonth() + 1,
       datenew Date().getDate()
    }
  },
  mounted() {
 // 获取农历
    this.getLunarDay = getLunar(this.year, this.month, this.date)
    console.log(this.getLunarDay)
  }
}
</script>

输出

在Vue项目中获取当前日期的农历(阴历)

需要哪个值就取哪个值哦O(∩_∩)O

  • dateStr: “二月廿五” //农历中文
  • isLeap: false //是否闰月
  • lunarDate: 25 //农历日期
  • lunarMonth: 2 //农历月份
  • lunarYear: “辛丑年” //农历年份,年以正月初一开始
  • solarTerm: null //节气,null代表没有
  • zodiac: “牛” //生肖,生肖以正月初一开始

原理

这个库是通过抓取香港天文台 (http://data.weather.gov.hk/gts/time/calendar/text/T2019c.txt) 的数据, 把每年闰月月份和每月的大小保存下来编码压缩,先解压生成数据表,再通过查表算出农历日期和节气

附:chinese-lunar-calendar地址(https://www.npmjs.com/package/chinese-lunar-calendar)

————————————————

版权声明:本文为CSDN博主「Winifred Wang」的原创文章

原文链接:https://blog.csdn.net/weixin_44483624/article/details/115455486


原文始发于微信公众号(前端24):在Vue项目中获取当前日期的农历(阴历)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/216549.html

(0)
李, 若俞的头像李, 若俞

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!