userRegist_hg.getYearWeek = function(d){
//var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
var DoW = d.getDay();
d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // Thu in Week 1
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
}
d指代传过来的Date类型的变量,返回周数!
//var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
var DoW = d.getDay();
d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // Thu in Week 1
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
}
d指代传过来的Date类型的变量,返回周数!
本文介绍了一个JavaScript函数,该函数接收一个Date类型的参数并返回该日期所在年的第几周。通过调整日期使得每周从星期四开始计算,以便确定任何日期所属的具体周数。
2112

被折叠的 条评论
为什么被折叠?



