Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/07/2012, 01:40
JohnEdiSantDe
 
Fecha de Ingreso: julio-2012
Mensajes: 8
Antigüedad: 11 años, 9 meses
Puntos: 0
Problema: Ingresar reloj y fecha javascript en base de datos

Hola tengo un problema al ingresar la hora y fecha en una base de datos , y no se realmente porque motivo sea.Si alguien me pudiera ayudar se lo agradecería :

En mi base de datos la hora y fecha la trabajo como String.

El código que utilizo es el siguiente:

Código Javascript:
Ver original
  1. <script language="JavaScript">
  2.             <!--
  3.             function show5(){
  4.  
  5.                 var Digital=new Date();
  6.                 var hours=Digital.getHours();
  7.                 var minutes=Digital.getMinutes();
  8.                 var seconds=Digital.getSeconds();
  9.                 var dn="AM";
  10.  
  11.                 str_hours= new String(hours)
  12.                 if (str_hours>12){
  13.                     dn="PM";
  14.                     str_hours=str_hours-12;
  15.                 }
  16.  
  17.                 if (str_hours<=9)
  18.                     str_hours="0"+str_hours;
  19.  
  20.                 if (str_hours==0)
  21.                     str_hours=12;
  22.  
  23.                  str_minutes= new String(minutes)
  24.                 if (str_minutes<=9)
  25.                     str_minutes="0"+str_minutes;
  26.  
  27.                 if (seconds<=9)
  28.                     seconds="0"+seconds;
  29.  
  30.                 myclock=str_hours+":"+str_minutes+" "+dn
  31.  
  32.                 document.principal.txtHora.value = myclock
  33.  
  34.                 setTimeout("show5()",1000)
  35.             }
  36.  
  37.             //-->
  38.         </script>

Código Javascript:
Ver original
  1. <!--Fecha desde lado del Cliente -->
  2.         <script>
  3.  
  4.             function show4(){
  5.  
  6.                 var mydate=new Date();
  7.                 var year=mydate.getYear();
  8.                 if (year < 1000)
  9.                     year+=1900;
  10.                 var day=mydate.getDay();
  11.                 var month=mydate.getMonth()+1;
  12.                 if (month<10)
  13.                     month="0"+month;
  14.                 var daym=mydate.getDate();
  15.                 if (daym<10)
  16.                     daym="0"+daym;
  17.  
  18.                 fecha=daym+"/"+month+"/"+year
  19.                 document.principal.txtFecha.value = fecha
  20.  
  21.             }
  22.         </script>


Código HTML:
Ver original
  1. <body onLoad="show5(); show4()" onLoad="show4()">
  2. <form action="<%=request.getContextPath()%>/CtrlHora"  name="principal">
  3. <p>
  4.                                             <label>Fecha</label>
  5.                                             <input type="text" id="txtFecha" name="txtFecha" >
  6.                                         </p>
  7.                                         </tr>
  8.  
  9.                                         <tr>
  10.                                         <p>
  11.                                             <label>Hora</label>
  12.                                             <input type="text" id="txtHora" name="txtHora" >
  13.                                         </p>
  14.                                         </tr>
  15.  
  16.  <p align="center">
  17.                 <input type="submit" name="accion" class="btn" value="Registrar"/>
  18.             </p>
  19.  
  20.  
  21. </body>
  22. </form>

Última edición por JohnEdiSantDe; 19/07/2012 a las 01:46