0
My date format ta yyyy-mm-dd
and I want to change to dd-mm-yyyy
I’m pulling the data from an api, so I put it with the "-" example: 2017-12-31 because before it only came with 20171231
but I want to change to 31-12-2017
First I pull the API to my website:
function load() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "API AQUI");
xhr.addEventListener("load", function() {
var resposta = xhr.responseText;
console.log("ola1");
var clientes = JSON.parse(resposta);
console.log("ola2");
console.log(clientes);
for (var i =0; i < 1; i++){
console.log("ola3");
var clientes_1 = clientes.TRACKER[i];
adicionaClienteNaTabelaEntregue(clientes_1);
console.log("ola4");
}
});
xhr.send();
}
window.onload = load;
Then I put it on my table
function adicionaClienteNaTabelaEntregue(cliente) {
// var pacienteTr = montaTr(cliente);
var clienteTr = montaTr(cliente);
var tabela = document.querySelector("#tabela-clientes");
tabela.appendChild(clienteTr);
}
function montaTr(cliente) {
var clienteTr = document.createElement("tr");
clienteTr.classList.add("cliente");
clienteTr.appendChild(montaTd(cliente.DTAENT, "info-entconfirmada"));
clienteTr.appendChild(montaTd(cliente.DTAMONORC, ".info-montprevista"));
clienteTr.appendChild(montaTd(cliente.DTAMON, ".info-montconfirmada"));
clienteTr.appendChild(montaTd(cliente.FILORC, "info-loja"));
return clienteTr;
}
function montaTd(dado, classe) {
var td = document.createElement("td");
td.classList.add(classe);
td.textContent = dado;
return td;
}
And the API data comes like this:
DTAMON:"2017-07-24"
DTAMONORC:"2017-07-12"
DTAPREENT:"2017-07-14"
Possible duplicate of How to format date in javascript?
– Luiz Santos