VUE獲取當前日期的周一和周天


weekCheckingIn(){ this.weekChecking_inloading = true var now = new Date(); var nowTime = now.getTime() ; var day = now.getDay()|| 7;// 不加 || 7.周末會變成下周一 var oneDayTime = 24*60*60*1000 ; var MondayTime = nowTime - (day-1)*oneDayTime ;//顯示周一 var SundayTime = nowTime + (7-day)*oneDayTime ;//顯示周日 //調用方法 console.log(this.formatDate(new Date(MondayTime))), console.log(this.formatDate(new Date(SundayTime))) } //格式化日期:yyyy-MM-dd formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth() + 1; var myweekday = date.getDate(); if (mymonth < 10) { mymonth = "0" + mymonth; } if (myweekday < 10) { myweekday = "0" + myweekday; } return (myyear + "-" + mymonth + "-" + myweekday); }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM