How to get the current time and current date to work? I can\'t get it file to sh
ID: 3776188 • Letter: H
Question
How to get the current time and current date to work? I can't get it file to show up on browser. This is the java code given.
<html>
<head><title>time</title></head>
<body>
<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); //space is required after new keyword
function GetClock(){var d=new Date(); //Date class it should be
var nday=d.getDay(),nmonth=d.getMonth(),nyear=d.getYear();
if(nyear<1000)nyear+=1900;
var nhour=d.getDay(), nmin=d.getMinutes(), nsec=d.getSeconds(60);
if(nmin<=9)nmin="0"+nmin
if(nsec<=9)nsec="0"+nsec;
document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+nday+" "+nyear+" "+nhour+":"+nmin+":"+nsec; //ndate is not declared, it should be nday
}
window.onload=function(){GetClock();
setInterval(GetClock,1000);
}
</script>
</body>
</html>
Explanation / Answer
<html>
<head><title>time</title></head>
<body>
<!--div element to show the clock-->
<div id="clockbox">
</div>
<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); //space is required after new keyword
function GetClock(){var d=new Date(); //Date class it should be
var nday=d.getDay(),nmonth=d.getMonth(),nyear=d.getYear();
if(nyear<1000)nyear+=1900;
var nhour=d.getDay(), nmin=d.getMinutes(), nsec=d.getSeconds(60);
if(nmin<=9)nmin="0"+nmin
if(nsec<=9)nsec="0"+nsec;
/*clockbox id should be present in the html to show the date and time*/
document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+nday+" "+nyear+" "+nhour+":"+nmin+":"+nsec; //ndate is not declared, it should be nday
}
window.onload=function(){GetClock();
setInterval(GetClock,1000);
}
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.