0

Hi, can someone help me? i wrote a function to print the day & time in the browser but it prints just the time.

22nd Aug 2019, 3:46 PM
Ahmad
Ahmad - avatar
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 : )
22nd Aug 2019, 4:14 PM
Ipang
+ 1
thanks dear 🙏both of you🙏
22nd Aug 2019, 10:58 PM
Ahmad
Ahmad - avatar
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 );
22nd Aug 2019, 3:48 PM
Ahmad
Ahmad - avatar