39 lines
958 B
JavaScript
39 lines
958 B
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
function mostrarFecha() {
|
|
const hoy = new Date();
|
|
|
|
const opciones = {
|
|
weekday: 'long',
|
|
day: 'numeric',
|
|
month: 'long',
|
|
year: 'numeric'
|
|
};
|
|
|
|
const fechaFormateada = hoy.toLocaleDateString('es-ES', opciones);
|
|
|
|
const divFecha = document.getElementById('fecha');
|
|
if (divFecha) {
|
|
divFecha.textContent = fechaFormateada;
|
|
}
|
|
}
|
|
|
|
function actualizarHora() {
|
|
const ahora = new Date();
|
|
|
|
const horas = String(ahora.getHours()).padStart(2, '0');
|
|
const minutos = String(ahora.getMinutes()).padStart(2, '0');
|
|
const segundos = String(ahora.getSeconds()).padStart(2, '0');
|
|
|
|
const horaFormateada = `${horas}:${minutos}:${segundos}`;
|
|
|
|
const divHora = document.getElementById('hora');
|
|
if (divHora) {
|
|
divHora.textContent = horaFormateada;
|
|
}
|
|
}
|
|
|
|
mostrarFecha();
|
|
actualizarHora();
|
|
setInterval(actualizarHora, 1000);
|
|
}); |