功能:要获取传入new Date()格式时间的前一周,前一个月等时间。
如获取上个月的最后一天new Date(this.time.getFullYear(), this.time.getMonth(), 0)
this.time为控件返回的中国标准时间,times是copy的时间
刚开始我是直接new Date(this.time.getFullYear(), this.time.getMonth(), 0)
后面输出,发现this.time被修改了,查阅各种资料,大概知道了原因
原因
new Date()是个对象,对象就存在深拷贝浅拷贝的问题,使用平常的方法
JSON.parse(JSON.stringify(New Ddate()))来解决的话,发现最后的格式不对
解决办法:拷贝一份时间出来
let times = new Date(this.time.valueOf());