const isDate = function(date) {
if (date === null || date === undefined) return false;
if (isNaN(new Date(date).getTime())) return false;
if (Array.isArray(date)) return false;
return true;
};
const getWeekNumber = function(src) {
if (!isDate(src)) return null;
const date = new Date(src.getTime());
date.setHours(0, 0, 0, 0);
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
const week1 = new Date(date.getFullYear(), 0, 4);
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
const d = getWeekNumber(new Date());
console.log(d);
};
console.log(new Date()); // 传日期对象
element 获取当前日是第几周
于 2022-03-07 09:39:15 首次发布