How to show Time With changing minutes and seconds?

0

I am assigning the value of the date and time to a text field using javascript, however instead of being a static value in the field, I would like the time to be constantly updated (for a query topic in the database) How could I do that?

I am currently showing the date and time of this form

var today = moment().format('YYYY-MM-DD HH:mm:ss');
document.getElementById("fecha_registro").value = today; 
    
asked by CristianOx21 09.11.2017 в 22:24
source

2 answers

1

Update

Do it again from scratch and on a completely blank page, copy the code as it is and it should work. if it does not work like this, check your parameters and / or settings:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Reloj con segundero dinamico</title>

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<script language="JavaScript"> 

    function mueveReloj(){ 
        momentoActual = new Date() 
        hora = momentoActual.getHours() 
        minuto = momentoActual.getMinutes() 
        segundo = momentoActual.getSeconds() 

        horaImprimible = hora + " : " + minuto + " : " + segundo 

        document.form_reloj.reloj.value = horaImprimible 

        //La función se tendrá que llamar así misma para que sea dinámica, 
        //de esta forma:

        setTimeout(mueveReloj,1000)
    }

</script> 

</head> 

<body onload="mueveReloj()"> 

    <form name="form_reloj"> 
        <input type="text" name="reloj" size="10"> 
    </form> 

</body>
</html>
    
answered by 09.11.2017 в 23:18
0

I left it in this way, so the module does not become slow

 var today = moment().format('YYYY-MM-DD');

 function new_clock(){ 

 clock = new Date() 
 hour =   clock.getHours() 
 minutes = clock.getMinutes() 
 seconds = clock.getSeconds() 

 print_clock = today + " " + hour + ":" + minutes + ":" + seconds 

 document.subida.fecha_registro.value = print_clock
 setTimeout(new_clock, 1000)
 }

 setTimeout(new_clock, 1000)

HTML

   <div class="col-md-2">
    <div class="form-group"  onload="new_clock()">

       <input type="text" class="form-control" id="fecha_registro" name="fecha_registro"   >   
    </div>
  </div>
    
answered by 10.11.2017 в 16:06