Wednesday, November 12, 2014

Today's Time Using JavaScript

In this article I would like to share with you a sample program that I wrote using JavaScript as my programming language. I called this program Today's Time what this program will do is to display the current time in your computer. For your information the date and time is being stored in our computer bios and powered by a battery called CR2032 3 volts.  

The code can be used to add functionality to your webpage by providing the visitor or user of your website to know what is the present time. If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

Thank you very much and Happy Programming.

Sample Output of Our Program

Program Listing

<html>
<script>
function clock(){
var time = new Date()
var hr = time.getHours()
var min = time.getMinutes()
var sec = time.getSeconds()
var ampm = " PM "
if (hr < 12){
ampm = " AM "
}
if (hr > 12){
hr -= 12
}
if (hr < 10){
hr = " " + hr
}
if (min < 10){
min = "0" + min
}
if (sec < 10){
sec = "0" + sec
}
text = hr + ":" + min + ":" + sec + ampm
document.getElementById("time").innerHTML ="The time is " + text;
setTimeout("clock()", 1000)
}
window.onload=clock;
</script>
<body onload="clock()"> 
<font face="arial" size=6" color="blue">
 <p id="time">  
</p> 
</font> 
</body>
</html>






No comments:

Post a Comment