How can I automatically set a date and time on my html table? Doing for js.
I created a table by js and inserted it in my API data, only that data goes to the TD part of the table, and I need to put the date and time it was inserted, and I have to put in the TH part of the table.
<tr class="cliente">
<th class="cor">Quantidade</th>
</tr>
<tr class="clientess">
<th class="cor">Nº.Pedido</th>
</tr>
Then in that part of th you have to automatically go to the date and time. The td from there I put through the javascript:
function AdicionaNotaFiscal(fiscal) {
var notaTr = fiscalTr(fiscal);
var tabelas = document.querySelector(".fiscal");
tabelas.appendChild(notaTr);
}
function fiscalTr(fiscal) {
var notaTr = document.createElement("tr");
notaTr.classList.add("fiscal");
notaTr.appendChild(notaTd(fiscal.NFISCA, "info-nota-fiscal"));
return notaTr;
}
function notaTd(dado, classe) {
var teste = document.querySelector(".fiscal");
var td = document.createElement("td");
td.classList.add(classe);
td.textContent = dado;
return td;
}
Then I pulled the API:
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];
adicionaClienteNaTabelaViagem(clientes_1);
adicionaClienteNaTabelaViagemLogo(clientes_1);
AdicionaNotaFiscal(clientes_1);
AdicionaEntPrevista(clientes_1);
AdicionaStatus(clientes_1);
// AdicionaNova();
// adicionaClientesNaTabelaViagemStatus(clientes_1);
console.log("ola4");
}
});
And I made a variable to add the time and date:
var data = new Date();
var dia = data.getDate();
var mes = data.getMonth();
var ano = data.getFullYear();
var hora = data.getHours();
var min = data.getMinutes();
var seg = data.getSeconds();
var str_data = dia + '/' + (mes+1) + '/' + ano;
var str_hora = hora + ':' + min;
But I do not know how to put this in my html table