1
Eae you guys, beauty?
I have a problem here, everything was working normally and suddenly started this problem.
Follows below the function:
function atualizaHoraServidor() {
var dia = digital.getDate();
var mes = digital.getMonth();
var ano = digital.getFullYear();
var horas = digital.getHours();
var minutos = digital.getMinutes();
var segundos = digital.getSeconds();
// aumenta 1 segundo
digital.setSeconds(segundos + 1);
// acrescento zero
if (dia <= 9) dia = "0" + dia;
if (mes <= 9) mes = "0" + mes;
if (mes == 0) mes = "0" + mes;
if (horas <= 9) horas = "0" + horas;
if (minutos <= 9) minutos = "0" + minutos;
if (segundos <= 9) segundos = "0" + segundos;
dispTime = dia + "/" + mes + "/" + ano + " " + horas + ":" + minutos + ":" + segundos;
$('#horarioServidor .horarioRelogio').text(dispTime);
setTimeout("atualizaHoraServidor()", 1000); // chamo a função a cada 1 segundo
}
What happens is he’s returning the date this way:
20/000/2017 16:08:26
The day and time is right, just giving problem in the month and year. It keeps updating straight on the site, IE, fica correr os segundos la....
Does anyone know what it might be? Some function that replaces getMonth and getFullYear?
I do not know if I am wrong, but I believe that this only occurs for the month of DECEMBER, previous month was normal.
I would like to see what is coming in this digital variable. Anyway I would draw the line if (mes == 0) mes = "0" + mes;
– Reginaldo Rigo
var digital = new Date(<?php echo str_replace(':',', ', str_replace('/',', ', str_replace(' ',', ', $Hora_Servidor_MySQL))).', 0'; ?>);
– Wendler
I tried to take that line but it didn’t work...
– Wendler
Take the two lines that treats the month to see how the dispTime variable is formatted.
– Reginaldo Rigo
Just decreased the zeroes, was like this: 20/0/2017 16:32:54
– Wendler
Show what is coming in the variable
$Hora_Servidor_MySQL
– Augusto
$Hora_Servidor_MySQL = date('Y/m/d H:i:s');
– Wendler
The time is displayed by a div, thus:
<div id="horarioServidor"><div class="horarioRelogio"></div></div>
– Wendler
Yes, it starts from zero until 11, being 0 for January and 11 for December, this I saw in the document... But you say change where exactly?
– Wendler
You have to change the month to subtract 1 before moving to
new Date()
, and change again by incrementing 1 before passing the content to thediv
, it’s easier to follow Pedro’s solution.– Augusto
Can you pass me the way you said? Because I couldn’t do it the other way.
– Wendler