前端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

原文地址:https://www.cnblogs.com/pzw23/p/13529653.html