On my website, I want the time to be shown live and update automatically without needing to refresh the page.
I have in the header of index.php the following:
<script src="/../scripts/time.js"></script>
time.js is the script below:
var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
document.write(hours + ":" + minutes)
It indeed shows correctly the current time, but it does not update without refreshing/reloading the web page. I believe it should actually be updating automatically since it is in JavaScript (which is known to able to do so).
What might I have done wrong?