反正有没有用JavaScript获取一年中的最后一个日历周?
例如今年“ 52”。
答案 0 :(得分:0)
这将返回年份的最后一周。
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
var lastDate = new Date("12/31/" + this.getFullYear());
var dayOfYear = ((lastDate - onejan +1)/86400000);
return Math.ceil(dayOfYear/7)
};
jQuery(function(){
var lastDate = new Date();
var weekno = lastDate.getWeek();
$("#weekNo").html(weekno);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="weekNo"></div>
答案 1 :(得分:0)
您可以执行以下操作:
function getStartingWeek(year, week) {
let tmp = new Date(year, 0, 1);
tmp.setDate(tmp.getDate() - tmp.getDay() + week * 7);
return tmp;
}
getStartingWeek(2018, 52) // give the ending day date of the 52th week of the year 2018