Ver Mensaje Individual
  #9 (permalink)  
Antiguo 20/06/2009, 10:43
Avatar de willyfc
willyfc
 
Fecha de Ingreso: octubre-2008
Ubicación: Santa Cruz - Bolivia
Mensajes: 662
Antigüedad: 15 años, 6 meses
Puntos: 40
Respuesta: Insertar codigo php en html

obviamente que si lo hace con un lenguaje del lado del servidor (independientemente de cual quiera utilizar) no verá la hora en tiempo real a no ser que se recargue toda la página, pero, no es necesario utilizar ajax y mucho menos cargar la web con un framework que solo hará ese trabajo, esto se logra con simple javascript puro:

Código html:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Fecha y hora</title>
  5. <script type="text/javascript">
  6. function hoy(){
  7.     var fechaActual = new Date();
  8.     dia = fechaActual.getDate();
  9.     mes = fechaActual.getMonth()+1;
  10.     anno = fechaActual.getFullYear();
  11.     if (dia <10) dia = "0" + dia;
  12.    if (mes <10) mes = "0" + mes;
  13.    fechaHoy = dia + "/" + mes + "/" + anno;  
  14.    return fechaHoy;
  15. }
  16. function mueveReloj(){
  17.    var momentoActual = new Date();
  18.     if(momentoActual.getHours()) var hora=String(momentoActual.getHours());
  19.     else{
  20.         var cadena=String(momentoActual);
  21.         var hora = String(cadena.substring(10,12));
  22.     }
  23.     //document.getElementById('hora').innerHTML= hora;//typeof(momentoActual);
  24.    var minuto = String(momentoActual.getMinutes());
  25.    var segundo = String(momentoActual.getSeconds());
  26.    if (segundo.length == 1)
  27.       segundo = "0" + segundo;
  28.    if (minuto.length == 1)
  29.       minuto = "0" + minuto;
  30.    if (hora.length == 1)
  31.       hora = "0" + hora;
  32.    horaImprimible = " "+hora + " : " + minuto + " : " + segundo;
  33.    document.getElementById('hora').innerHTML= horaImprimible;
  34.    setTimeout("mueveReloj()",1000);
  35. }
  36. </head>
  37.  
  38. <body onload="mueveReloj();">
  39.             <script type="text/javascript">hoy();document.write("<strong>Fecha:</strong> "+fechaHoy+"");</script><br />
  40.             <strong>Hora: </strong><span id="hora"></span><br />
  41. </body>
  42. </html>

solo tendría que bastar con eso.

Edito:Coloque todo en un solo archivo para que sea mas entendible
__________________
WFC
codigo82

Última edición por willyfc; 20/06/2009 a las 10:49