0

Necesito modificar este reloj que no salgan las 17:10 si no las 5 y 10, alguna manera:

 function startTime(){
                today=new Date();
                h=today.getHours();
                m=today.getMinutes();
                m=checkTime(m);
                document.getElementById('reloj').innerHTML=h+":"+m;
                t=setTimeout('startTime()',500);}
                function checkTime(i)
                {if (i<10) {i="0" + i;}return i;}
                window.onload=function(){startTime();}
 <div id="reloj" style="font-size:20px;"></div>

2 respuestas 2

2

Te dejo un script, espero te sirva.

function actualizaReloj(){ 

/* Capturamos la Hora, los minutos y los segundos */
marcacion = new Date() 

/* Capturamos la Hora */
Hora = marcacion.getHours() 
meridium=(Hora>12)?"pm":"am";
Hora =Hora%12
if(Hora==0){Hora=12}


/* Capturamos los Minutos */
Minutos = marcacion.getMinutes() 

/* Capturamos los Segundos */
Segundos = marcacion.getSeconds() 

/* Si la Hora, los Minutos o los Segundos
Son Menores o igual a 9, le añadimos un 0 */

if (Hora<=9)
Hora = "0" + Hora

if (Minutos<=9)
Minutos = "0" + Minutos

if (Segundos<=9)
Segundos = "0" + Segundos

/* Creamos 4 variables para darle formato a nuestro Script */
var Script, Final, Total

/*En Inicio le indicamos un color de fuente y un tamaño */
Inicio = "<font size=3 color=red>"

/* En Reloj le indicamos la Hora, los Minutos y los Segundos */
Script = Hora + ":" + Minutos + ":" + Segundos +meridium

/* En final cerramos el tag de la fuente */
Final = "</font>"

/* En total Finalizamos el Reloj uniendo las variables */
Total = Inicio + Script + Final

/* Capturamos una celda para mostrar el Reloj */
document.getElementById('Fecha_Reloj').innerHTML = Total

/* Indicamos que nos refresque el Reloj cada 1 segundo */
setTimeout("actualizaReloj()",1000) 
}
</script>
<body onload="actualizaReloj()">
Aquí mostramos la Fecha y la hora:
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td id="Fecha_Reloj"></td>
</tr>
</table>
</body>

0

Puedes usar una función sencilla y hacer lo siguiente:

function startTime(){
   var today = new Date();
   var h = hours12(today);
   //tu demás código aquí :)
}

function hours12(date) { 
   return (date.getHours() + 24) % 12 || 12; 
}

Sólo fue cuestión de usar las matemáticas.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.