Created
December 11, 2018 12:57
-
-
Save LucasJorgeHubert/e83eba3f75cf5e0401ea5bee448693c1 to your computer and use it in GitHub Desktop.
Para retornar o primeiro e o último dia da semana (domingo - sábado), com as datas completas, código mais didático possível.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instanciar a data de hoje | |
let today = new Date(); // Tue Dec 11 2018 10:54:05 GMT-0200 (Horário de Verão de Brasília) | |
// Instanciar a data de domingo da semana corrente | |
let firstDayOfWeek = new Date(); | |
firstDayOfWeek.setDate(today.getDate() - today.getDay()/** 2 */); | |
firstDayOfWeek.setMonth(today.getMonth()); | |
// Sun Dec 09 2018 10:54:05 GMT-0200 (Horário de Verão de Brasília) | |
// Instanciar a data de sábado da semana corrente | |
let lastDayOfWeek = new Date(); | |
lastDayOfWeek.setDate(today.getDate() + (6 - today.getDay()/** 2 */)); | |
lastDayOfWeek.setMonth(today.getMonth()); | |
//Sat Dec 15 2018 10:54:05 GMT-0200 (Horário de Verão de Brasília) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment