Reloj en JavaScript


<html>
<head>
<title>Reloj con Javascript</title>
<script language=”JavaScript”>
function reloj(){
ahora = new Date()
hora = ahora.getHours()
minuto = ahora.getMinutes()
segundo = ahora.getSeconds()

<!–Si los digitos del segundo son 1, entonces se concatena un “0″–>
str_segundo = new String (segundo)
if (str_segundo.length == 1)
segundo = “0″ + segundo

<!–Si los digitos del minuto son 1, entonces se concatena un “0″–>
str_minuto = new String (minuto)
if (str_minuto.length == 1)
minuto = “0″ + minuto

<!–Si los digitos de la hora son 1, entonces se concatena un “0″–>
str_hora = new String (hora)
if (str_hora.length == 1)
hora = “0″ + hora

mostrarHora = hora + ” : ” + minuto + ” : ” + segundo

document.form_reloj.reloj.value = mostrarHora

setTimeout(“reloj()”,1000)
}
</script>
</head>

<body onload=”reloj()”>

<form name=”form_reloj”>
<input type=”text” name=”reloj” onfocus=”window.document.form_reloj.reloj.blur()”>
</form>

</body>
</html> 

Advertisement

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s


Seguir

Get every new post delivered to your Inbox.