-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.html
More file actions
73 lines (68 loc) · 2.44 KB
/
Copy pathjava.html
File metadata and controls
73 lines (68 loc) · 2.44 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Controle de Tempo</title>
<link rel="stylesheet" href="css.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400..900&display=swap" rel="stylesheet">
</head>
<body>
<h1>Agora são exatamente:</h1>
<h2 id="relogio"></h2>
<h3></h3><h3 id="agora"></h3>
<script>
function atualizarRelogio(){
const agora = new Date();
const horas = agora.getHours().toString().padStart(2, '0');
const minutos = agora.getMinutes().toString().padStart(2 , '0');
const segundos = agora.getSeconds().toString().padStart(2, '0');
document.getElementById("relogio").innerText = `${horas}:${minutos}:${segundos}`;
}
setInterval(atualizarRelogio, 1000);
atualizarRelogio();
</script>
<hr>
<h2 id="cronometro">00:00:00</h2>
<div>
<button onclick="iniciar()" id="btIniciar">Iniciar</button>
<button onclick="pausar()" id="btPausar">Pausar</button>
<button onclick="zerar()" id="btZerar">Zerar</button>
</div>
<script>
let segundos = 0;
let intervalo;
function formatarTime(segundos){
const h = String(Math.floor(segundos/3600)).padStart(2, '0');
const m = String(Math.floor((segundos % 3600)/60)).padStart(2, '0');
const s = String(segundos % 60).padStart(2, '0');
return `${h}:${m}:${s}`;
}
function atualizarCronometro(){
document.getElementById("cronometro").innerText = formatarTime(segundos);
}
function iniciar(){
if(!intervalo){
intervalo = setInterval(() => {
segundos++;
atualizarCronometro();
}, 1000);
}
}
function pausar(){
if(intervalo){
clearInterval(intervalo);
intervalo = null;
}
}
function zerar(){
pausar();
segundos = 0
atualizarCronometro();
}
document.getElementById()
</script>
</body>
</html>