-2
I am putting the date on the site with this code that is working, but this script has to be inside the HTML element in which the date will appear.
How can I change this script so that the date appears on a DIV
identified by your ID
?
var now = new Date();
var mName = now.getMonth() +1 ;
var dName = now.getDay() +1;
var dayNr = now.getDate();
var yearNr=now.getYear();
if(dName==1) {Day = "Domingo";}
if(dName==2) {Day = "Segunda-feira";}
if(dName==3) {Day = "Terça-feira";}
if(dName==4) {Day = "Quarta-feira";}
if(dName==5) {Day = "Quinta-feira";}
if(dName==6) {Day = "Sexta-feira";}
if(dName==7) {Day = "Sábado";}
if(mName==1){Month = "Janeiro";}
if(mName==2){Month = "Fevereiro";}
if(mName==3){Month = "Março";}
if(mName==4){Month = "Abril";}
if(mName==5){Month = "Maio";}
if(mName==6){Month = "Junho";}
if(mName==7){Month = "Julho";}
if(mName==8){Month = "Agosto";}
if(mName==9){Month = "Setembro";}
if(mName==10){Month = "Outubro";}
if(mName==11){Month = "Novembro";}
if(mName==12){Month = "Dezembro";}
if(yearNr < 2000) {Year = 1900 + yearNr;}
else {Year = yearNr;}
var todaysDate =(" " + "São Paulo, " + dayNr + " de " + Month + " de " + Year + " - " + Day );
document.write(' '+todaysDate);
<!DOCTYPE html>
<html>
<body>
<!-- A data entraria nesta DIV -->
<div id="todaysDate">" "</div>
</body>
</html>
Already tried something like at the end of the code, Document.getElementById('todaysDate'). innerHTML = todaysDate
– Pedro Henrique
Possible duplicate of Help with innerHTML in Javascript
– Darlei Fernando Zillmer
Thanks for the help Henriquuepedro and Darlei Fernando Zilmer, I’ve changed here and it’s ok
– M. Nunes