-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
43 lines (36 loc) · 835 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function mostrarHora(){
let dia = new Date();
let hora = dia.getHours();
let minutos = dia.getMinutes();
let segundos = dia.getSeconds();
let formatoHora = convertaFormato(hora);
hora = verificaHora(hora);
hora = addZero(hora);
minutos = addZero(minutos);
segundos = addZero(segundos);
document.getElementById('clock').innerHTML = `${hora}:${minutos}:${segundos}${formatoHora}`
}
function convertaFormato(time){
let formato = "AM";
if(time >= 12){
formato = "PM";
}
return formato;
}
function verificaHora(time){
if(time>12){
time = time - 12;
}
if (time === 0){
time = 12;
}
return time;
}
function addZero(time){
if(time<10){
time = "0" + time;
}
return time;
}
mostrarHora()
setInterval(mostrarHora,1000);