1
I’m willing to display the current date on a particular div while loading the page, I have already made a working sketch of the code, but I am using the button. I followed the code:
function formataData(data = new Date()){
var dia = data.getDate();
var mes = data.getMonth()+1;
var ano = data.getFullYear();
if(dia.toString().length == 1) dia = '0'+dia;
if(mes.toString().length == 1) mes = '0'+mes;
return dia+'/'+mes+'/'+ano;
}
document.getElementById("btnData").addEventListener("click", function myFunction() {
document.getElementById("localData").innerHTML = formataData()
});
<p>Exibindo data atual.</p>
<button id="btnData">Exibir Data >></button>
<div id="localData" style="width: 100px; height: 50px; border: 1px solid #000;"></div>
I could trade this function for a simple
new Date().toLocaleDateString()
– Costamilam