Skip to content

Commit

Permalink
API reloj 'World Time API'
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinXCVI committed May 30, 2024
1 parent e14f7df commit 64e05bc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ nav ul li {
margin-right: 20px;
}

.reloj-div a {
color: white;
text-decoration: none;
transition: 0.3s;
padding: 1rem;
}

.reloj-div a:hover {
color: #ff4081;
cursor: pointer;

border-radius: 2rem;
background-color: white;
}

.search-span {
display: flex;
justify-content: center;
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<div class="logo">
<h1 class="hero-titulo" data-aos="fade-right"><a href="index.html"><i class="fa-solid fa-film"></i> PelículasCAC</a></h1>
</div>
<div class="reloj-div">
<a href="http://worldtimeapi.org/" target="_blank">
<i class="fa-regular fa-hourglass-half"></i>
<span id="reloj"> Cargando...</span>
</a>
</div>
<div class="search">
<span class="search-span">
<input type="search" placeholder="Buscar...">
Expand Down Expand Up @@ -270,6 +276,8 @@ <h4>SEGUINOS</h4>
</footer>

<!----------- SCRIPTS ------------>
<!---- JavaScript ---->
<script src="js/apis/reloj.js"></script>
<!---- Bootstrap scripts ---->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<!----- AOS scripts ------>
Expand Down
19 changes: 19 additions & 0 deletions js/apis/reloj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
async function obtenerHoraDelServidor() {
try {
const respuesta = await fetch('http://worldtimeapi.org/api/timezone/America/Argentina/Buenos_Aires');
const datos = await respuesta.json();
return datos.datetime.slice(11, 19); // Extraer solo la hora (HH:MM:SS)
} catch (error) {
console.error('Error al obtener la hora del servidor:', error);
return 'Error';
}
}

async function actualizarReloj() {
const hora = await obtenerHoraDelServidor();
const reloj = document.getElementById('reloj');
reloj.textContent = hora;
}

setInterval(actualizarReloj, 1000);
actualizarReloj();

0 comments on commit 64e05bc

Please sign in to comment.