Código :
var horaEv, horas, minutos, segundos, tServidor, tEvento;
var fecha = new Date();
function obtenerDia(){
var dia = fecha.getUTCDay();
return dia;
}
function obtenerHora(){
horas = fecha.getUTCHours();
minutos = fecha.getUTCMinutes();
segundos = fecha.getUTCSeconds();
horas -= 4;
}
function evento(horaEvento){
horaEv = horaEvento.split(":");
for(var i = 0; i < horaEv.length; i++){
horaEv[i] = parseInt(horaEv[i]);
}
}
function convertirASegundos(horas, minutos, segundos){
var tiempo;
tiempo = ((horas*3600) + (minutos*60)) + segundos;
return tiempo;
}
function convertirAHoras(tiempo, contenedor){
var h, m, s, aux;
h = Math.trunc(tiempo/3600);
m = Math.trunc((tiempo - (h*3600))/60);
s = Math.trunc(tiempo - ((h*3600) + (m*60)));
document.getElementById(contenedor).textContent = h+":"+m+":"+s;
}
function evaluarTiempos(tiempoServidor, tiempoEvento){
var eval;
if(tiempoServidor > tiempoEvento){
eval = false;
}
else{
eval = true;
}
return eval;
}
function tw(dia){
var bool, tEspera;
if(dia >= 0){
evento('13:30:00');
tServidor = convertirASegundos(horas, minutos, segundos);
tEvento = convertirASegundos(horaEv[0], horaEv[1], horaEv[2]);
tEspera = tEvento - tServidor;
bool = evaluarTiempos(tServidor, tEvento);
if(bool == false){
evento('17:00:00');
tServidor = convertirASegundos(horas, minutos, segundos);
tEvento = convertirASegundos(horaEv[0], horaEv[1], horaEv[2]);
tEspera = tEvento - tServidor;
bool = evaluarTiempos(tServidor, tEvento);
if(bool == false){
evento('21:00:00');
tServidor = convertirASegundos(horas, minutos, segundos);
tEvento = convertirASegundos(horaEv[0], horaEv[1], horaEv[2]);
tEspera = tEvento - tServidor;
bool = evaluarTiempos(tServidor, tEvento);
}
else{
convertirAHoras(tEspera, "hora");
}
}else{
convertirAHoras(tEspera, "hora");
}
}
}
function relojes(){
var dia = obtenerDia();
obtenerHora();
tw(dia);
var timer = setInterval(relojes, 1000);
}
document.addEventListener("DOMContentLoaded", relojes, false);
Código :
<html>
<head>
<meta charset="utf-8"/>
<link href="https://fonts.googleapis.com/css?family=Audiowide" rel="stylesheet">
<script src= "reloj1.2.js"></script>
<style type="text/css">
#hora{
font-family: 'Audiowide', cursive;
}
</style>
</head>
<body>
<div id="hora"></div>
</body>
</html>
de antemano gracias por la ayuda que me puedan dar.
NOTA: solo conosco el metodo setInterval para hacer lo que quiero, si alguien conoce alguna otra manera, pues estoy abierto a nuevas ideas
