Created
July 5, 2013 18:52
-
-
Save guillermo888/5936495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<form name="miform" id="miform"> | |
<label for="fecha1">Fecha N°1 </label><input type="text" name="fecha1" id="fecha1" placeholder="fecha 12:12:12" tabsindex="1" value="08:30:12"/><br/> | |
<label for="fecha2">Fecha N°2 </label><input type="text" name="fecha2" id="fecha2" placeholder="fecha 12:13:12" tabsindex="2" value="12:30:12"/><br/> | |
<label for="ahora">Tiempo actual</label><input type="text" id="ahora" name="ahora"/><br/><br/> | |
<label id="servicio" style="border:1px; font-size:14pt;">servicio desactivado</label><br/> | |
<label id="prueba">000</label> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeNow(){ | |
f=new Date(); | |
hora=f.getHours(); | |
minuto=f.getMinutes(); | |
segundo=f.getSeconds(); | |
tiempoImpreso=hora+':'+minuto+':'+segundo; | |
$("#ahora").val(tiempoImpreso); | |
setTimeout("timeNow()",1000); | |
} | |
function comprueba_estado(){ | |
j=new Date(); | |
hora=j.getHours(); | |
minuto=j.getMinutes(); | |
segundo=j.getSeconds(); | |
tiempoImpreso=hora+':'+minuto+':'+segundo; | |
f1=$("#fecha1").val(); | |
f2=$("#fecha2").val(); | |
//$("#prueba").text(tiempoImpreso); | |
if(evalua(f1,tiempoImpreso) && evalua(tiempoImpreso,f2)){ | |
$("#servicio").text("Servicio Activado"); | |
}else{ | |
$("#servicio").text("Servicio Desactivado"); | |
} | |
setTimeout("comprueba_estado()",1000); | |
} | |
//funcion que evalua si f_1 es menor o igual que f_2 | |
function evalua(f_1,f_2){ | |
h1=parseInt(f_1.substring(0,2)); | |
m1=parseInt(f_1.substring(3,5)); | |
h2=parseInt(f_2.substring(0,2)); | |
m2=parseInt(f_2.substring(3,5)); | |
//$("#prueba").text(h2); | |
//aqui cominzan los calculos | |
if(h1<h2){return true;} else{if(h1=h2){if(m1<=m2){return true;}else{return false;}}else{return false;}} | |
} | |
$(document).ready(function(){ | |
timeNow(); | |
comprueba_estado(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Este es un fragmento de código para poder comparar la hora actual con un rango de tiempo dado con anterioridad