0
Hi, can someone help me? i wrote a function to print the day & time in the browser but it prints just the time.
4 Réponses
+ 1
You change the innerHTML of the element ID:"timing" twice, first you put in year-month-day, next you put hour-minute-second. That's it I guess : )
+ 1
thanks dear 🙏both of you🙏
0
function printTime(){
let d = new Date();
let year = d.getFullYear();
let month = d.getMonth();
let day =d.getDay();
let hours = d.getHours();
let min = d.getMinutes();
let sec = d.getSeconds();
let date = document .getElementById("timing").innerHTML = year + "-" + month+ "-" + day;
let time = document .getElementById ("timing").innerHTML = hours + ":" + min + ":" + sec;
return date;
return time;
}
setInterval(printTime );