前端vuejs获取指定年月的第一天和最后一天(使用momentjs)


 首先需要在前端框架的package.json引入moment-timezone

然后需要在index.js文件里面导入moment-timezone

然后在使用的Vue文件里面导入moment-timezone

在Vue文件中,如果在HTML代码中使用,则需要在return里面定义moment

如果只是在js里面用,就直接用就行了。

 

 let currDate = moment("2020-08-14");
 console.log(currDate );
 this.dateRange.push(currDate.startOf("month").valueOf());//获取该月份第一天的时间戳
 this.dateRange.push(currDate.endOf("month").valueOf());//获取该月份最后一天的时间戳
 console.log(this.dateRange);

参考momentjs中文官网:http://momentjs.cn/docs/#/manipulating/start-of/

参考链接2:http://www.fly63.com/article/detial/5943

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM