Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
15.12
const getDateOfNearestDay = (day, date = new Date()) => new Date( date.getFullYear(), date.getMonth(), date.getDate() + ((7 + day - date.getDay()) % 7) ); const dateOfNearestSaturday = getDateOfNearestDay(6);
function getSaturday() { var today = new Date().getUTCDay(); var diff = 6 - today; if ([-1, 0].includes(Math.sign(diff))) { return new Date(new Date().setUTCDate(13 - today)); } return new Date(new Date().setUTCDate(diff)); }
const getSaturday = () => { let daysUntil = 6 - new Date().getDay(), date = new Date().toLocaleDateString().split("-"); date[2] = parseInt(date[2]) + daysUntil; return date.join("-"); }