<script> export default { data() { return { weekFormat: "" }; }, mounted() { console.log(this.getWeekStartAndEnd("2021-5-25")); }, methods: { // 日期格式化 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 mymonth + "." + myweekday; }, // 获取指定日期的那一周的开始、结束日期 getWeekStartAndEnd(val) { let now = ""; if (val) { now = new Date(val); // 日期 } else { now = new Date(); // 日期 } let nowDayOfWeek = now.getDay(); // 本周的第几天 let nowDay = now.getDate(); // 当前日 let nowMonth = now.getMonth(); // 当前月 let nowYear = now.getYear(); // 当前年 let weekStart = this.getWeekStartDate( nowYear, nowMonth, nowDay, nowDayOfWeek ); let weekEnd = this.getWeekEndDate( nowYear, nowMonth, nowDay, nowDayOfWeek ); this.weekFormat = weekStart + "~" + weekEnd; console.log("weekFormat", this.weekFormat); }, // 获得某一周的开始日期 getWeekStartDate(nowYear, nowMonth, nowDay, nowDayOfWeek) { let weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); return this.formatDate(weekStartDate); }, // 获得某一周的结束日期 getWeekEndDate(nowYear, nowMonth, nowDay, nowDayOfWeek) { let weekEndDate = new Date( nowYear, nowMonth, nowDay + (6 - nowDayOfWeek) ); return this.formatDate(weekEndDate); } } }; </script>
el-table利用:row-style="rowClass"设置指定行变色
一款免费开源效果酷炫的 Vue / React 大屏数据展示组件库——DataV
vue项目动态设置background背景色,解决颜色被替换问题
上面是“vuejs获取指定日期的那一周的开始、结束日期(从”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_101.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!