Skip to content

Instantly share code, notes, and snippets.

@LucasAlfare
Created January 5, 2023 16:16
Show Gist options
  • Save LucasAlfare/3231f08e17aa5008e571bff66f3b8991 to your computer and use it in GitHub Desktop.
Save LucasAlfare/3231f08e17aa5008e571bff66f3b8991 to your computer and use it in GitHub Desktop.
Esse código mostra na janela do navegador o dia de hoje.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Que dia é hoje?</title>
<h1 id="target">Calculando o dia de hoje...</h1>
<style>
h1 {
font-size: 100px;
}
</style>
</head>
<body>
<script>
const currentJokeYear = 2022;
const lastYearDay = new Date(`12 31 ${currentJokeYear}`);
const today = new Date();
const weekDays = [
"Domingo",
"Segunda-feira",
"Terça-feira",
"Quarta-feira",
"Quinta-feira",
"Sexta-feira",
"Sábado"
];
const hoursInOneDay = 24;
const minutesInOneDay = hoursInOneDay * 60;
const secondsInOneDay = minutesInOneDay * 60;
const millisecondsInOneDay = secondsInOneDay * 1000;
const daysDiffBetweenLastAndToday = today.getTime() - lastYearDay.getTime();
const currentRollingDay =
lastYearDay.getDate() + (Math.floor(daysDiffBetweenLastAndToday / millisecondsInOneDay));
const currentWeekDay = weekDays[today.getDay()];
const h1Ref = document.getElementById("target");
h1Ref.innerText = `${currentWeekDay}, ${currentRollingDay} de dezembro de ${currentJokeYear}.`
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment