0
Can you help me with a js script?
function printTime() { var d = new Date(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); document.body.innerHTML = hours+":"+mins+":"+secs; } setInterval(printTime, 1); When the seconds are <10 the browser writes 1,2 ,3 ,6, 9, however I want it to write 01, 05, 09 and so on. It's the same problem with the minutes. I tried it with the if statement. Can someone explain the code of rhis to me pls.
2 Antworten
+ 4
if (secs<9) secs="0" + secs
The same goes for minutes.
Also, the interval will work just fine if you set it at 1000.
0
I wrote it w document.body.innerHTML and it didnt work