function myFunction()
{
alert("page is loaded");
}
var myVar=setInterval(function(){myTimer()},1000);
function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
As you can see in the code the first thing is an alert box when first accessing the page, the box contains the text "page is loaded". The following code sets the timer and show the date. The time is shown in hour minutes and seconds. Regardless of whether it is PM or AM the code will make it so it recognizes the correct time and date and displays it accordingly on the web site.
No comments:
Post a Comment