1. 根据传入的时间,计算当天是该年的第几周
function getWeekOfYear(year, month, day) {
let m = month - 1;
let a = new Date(year, 0, 1);
a = a - 3600 * 24 * 1000 * a.getDay();
let b = new Date(year, m, day).getTime();
let c = Math.floor((b - a) / (3600 * 24 * 1000 * 7));
console.log(c + 1)
return (c + 1)
}
2. 根据传入的时间,计算当天的开始时间戳和结束时间戳
function getStartTimestamp (timestamp = Date.now()) {
const startTimestamp = new Date(new Date(timestamp).setHours(0, 0, 0, 0)).getTime();
const endTimestamp = new Date(new Date(timestamp).setHours(23, 59, 59, 999)).getTime();
return {startTimestamp, endTimestamp};
}
3. 使页面滚动到指定节点的位置
export function scrollToElementLocation(el, scrollEl, offsetTop = 300) {
const elOffsetTop = el.getBoundingClientRect().top;
const containerScrollHeight = scrollEl.scrollTop;
const scrollHeight = containerScrollHeight + elOffsetTop - offsetTop;
scrollEl.scrollTo({
let: 0,
top: scrollHeight,
behavior: "smooth",
})
}