I am creating a clock from an informed value, the problem is that the clock is not being updated.
The other problem is that in the inverted view, the month is coming first than the day.
What am I doing wrong? This "Today" value appears correctly and comes from the server, I can not get the value of the client because of the risk of changing the date of the computer.
function relogio() {
var valor = document.getElementById('Hoje').value;
var data = new Date(valor);
var dia = data.getDate();
var mes = data.getMonth() + 1;
var ano = data.getFullYear();
var horas = data.getHours();
var minutos = data.getMinutes();
var segundos = data.getSeconds();
if (dia < 10) {
dia = "0" + dia;
}
if (mes < 10) {
mes = "0" + mes;
}
if (horas < 10) {
horas = "0" + horas;
}
if (minutos < 10) {
minutos = "0" + minutos;
}
if (segundos < 10) {
segundos = "0" + segundos;
}
var dataAtualizada = dia + '/' + mes + '/' + ano + ' ' + horas + ':' + minutos + ':' + segundos;
document.getElementById('relogio').innerHTML = dataAtualizada;
}
window.setInterval(relogio(), 1000);