Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Commit

Permalink
Adicionado datas
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcon83 committed Mar 16, 2021
1 parent 2b9a70a commit 86291dc
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
116 changes: 116 additions & 0 deletions Dia 34 - JS - Datas/D34E1 - Datas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html>

<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name="author" content="Giovanni Marcon">

<title>Exercício datas</title>

<style>
input {
font-size: 1.3em;
width: 300px;
margin: 6px;
padding: 10px;
}

button {
font-size: 1.3em;
margin: 6px;
padding: 9px;
}
</style>

<script>

let input, display;
let data = new Date();
let agora = `O dia é ${pad(data.getDate() + 1, 2)}/${pad(data.getMonth() + 1, 2)}/${data.getFullYear()} - ${diaDaSemana(data.getDay())}`

// Atribui valores as variáveis após finalizar o carregamento da página
window.onload = () => {
input = document.getElementById("input");
display = document.getElementById("display");
document.getElementById("dia-de-hoje").innerHTML = agora
};

function mostrar() {
let dataIn = input.value;
let dataPart = dataIn.split("/");
let dataOut = `${dataPart[0]} de ${mes(dataPart[1])} de ${dataPart[2]}`;
display.value = dataOut
}

// Adiciona 0s
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}

function diaDaSemana(num) {
switch (num) {
case 0:
return "Domingo"
case 1:
return "Segunda-feira"
case 2:
return "Terça-feira"
case 3:
return "Quarta-feira"
case 4:
return "Quinta-feira"
case 5:
return "Sexta-feira"
case 6:
return "Sábado"
}
}

function mes(num) {
switch (num) {
case "1":
return "janeiro"
case "2":
return "fevereiro"
case "3":
return "março"
case "4":
return "abril"
case "5":
return "maio"
case "6":
return "junho"
case "7":
return "julho"
case "8":
return "agosto"
case "9":
return "setembro"
case "10":
return "outubro"
case "11":
return "novembro"
case "12":
return "dezembro"
}
}
</script>


</head>

<body>
<h1 id="dia-de-hoje"></h1>
<hr>
<input id="input" class="sem-foco" name="caixaInput" type="text" placeholder="DD/MM/AAAA">
<button onclick="mostrar()">Mostrar</button>
<input id="display" class="sem-foco" name="caixaInput" type="text" placeholder="Resultado aqui." readonly>
<hr>

</body>

</html>
20 changes: 20 additions & 0 deletions _JS - Datas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Datas são baseada em ms, contados desde 1 jan de 1970. Depois de criados
objetos data não atualizam o tempo automáticamente.

Declaraçoes:

var nomeVar = new Date()
var nomeVar = new Date(year, month, day, hours, minutes, seconds, milliseconds)
var nomeVar = new Date(milliseconds)
var nomeVar = new Date(date string)

Metodos:

.getDate // Retorna o dia do mês;
.getDay // Retorna o dia da Semana, inicia do 0;
.getFullYear // Retorna o ano com 4 digitos;
.getMonth // Retorna o mês, inicia do 0;
.getHours // Retorna as horas;
.getMinutes // Retorna os minutos;
.getSeconds // Retorna os segundos;
.getMilliseconds // Retorna os milisegundos;

0 comments on commit 86291dc

Please sign in to comment.