本文主要是介绍Vue获取当前时间( 年初-年末、月初-月末、),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 获取年初-年末、月初-月末、getNowTime() {var now = new Date();var year = now.getFullYear(); //得到年份var month = now.getMonth(); //得到月份var day = now.getDate(); //得到天if (day < 10) {day = "0" + day}month = month + 1;month = month.toString().padStart(2, "0");var defaultDate = `${year}-${month}`;this.value1 = defaultDate;this.value2 = defaultDate;this.value3 = defaultDate;this.value4 = defaultDate;this.value6 = defaultDate;this.today.date_from = `${year}-${month}-${day}`this.today.date_to = `${year}-${month}-${day}`this.month.date_from = `${year}-${month}-01`this.month.date_to = `${year}-${month}-31`this.year.date_from = `${year}-01-01`this.year.date_to = `${year}-12-31`console.log(this.today.date_from + '-today.date_from')console.log(this.today.date_to + '-today.date_to')console.log(this.month.date_from + '-month.date_from')console.log(this.month.date_to + '-month.date_to')console.log(this.year.date_from + '-year.date_from')console.log(this.year.date_to + '-year.date_to')// 对象不要直接赋值,其中涉及深浅拷贝原理switch (this.top_value) {case 1:this.date = JSON.parse(JSON.stringify(this.today));break;case 2:this.date = JSON.parse(JSON.stringify(this.month));break;case 3:this.date = JSON.parse(JSON.stringify(this.year));break;case 4:this.date.date_from = null;this.date.date_to = nullbreak;default:break;}},
这篇关于Vue获取当前时间( 年初-年末、月初-月末、)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!