htmledit_views">
html的week控件 获取周(星期)的第一天(周一)和最后一天(周日)
<input type="week" id="week" class="my-css" value="@ViewBag.DefaultWeek" />
<script>
function PageList() {
var dateString = $("#week").val();//控件值格式为: 'YYYY-WW',如:2024-W42
console.log("年度第几周", dateString);
var year = parseInt(dateString.substr(0, 4), 10);//截取字符串“年”的部分:2024
var week = parseInt(dateString.substr(6, 2), 10);//截取字符串“第几周”的部分:42
//计算日期
var jsDate = new Date(year, 0, (week - 1) * 7);//生成日期
var dayOfWeek = jsDate.getDay();
var dayOffset = dayOfWeek === 1 ? 0 : 1 - dayOfWeek;
var monday = new Date(jsDate.setDate(jsDate.getDate() + dayOffset + 1));//星期一日期
var sunday = new Date(jsDate.setDate(monday.getDate() + 6));//星期日日期(星期一+6天)
var StartDate = monday.toISOString().substr(0, 10);
var EndDate = sunday.toISOString().substr(0, 10);
console.log('星期一: ' + StartDate);
console.log('星期日: ' + EndDate);
}
</script>