Create A Clock With Javascript
Hello, I am learning java script by own. And I want to create a script which can provide me clock. If anybody knows code for this script then please provide me that. If you know the sources then also provide me. Suggest me some good books for basic javascrpt understanding.
Re: Create A Clock With Javascript
I think you may need to use javascript books below to get this solution :
- JavaScript Programmer's Reference
- Beginning JavaScript
- JavaScript: The Definitive Guide
- Instant JavaScript
- JavaScript Application Cookbook
- Learn Advanced JavaScript Programming
Re: Create A Clock With Javascript
The script below will provide you A clock in Javascript:
Code:
<html>
<head>
<script type="text/javascript">
function time()
{
var now=new Date();
var hr=now.getHours();
var minute=now.getMinutes();
var s=now.getSeconds();
minute=checkTime(minute);
seconds=checkTime(seconds);
document.getElementById('txt').innerHTML=h+":"+minute+":"+seconds;
t=setTimeout('time()',500);
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
</head>
<body onload="time()">
<div id="txt"></div>
</body>
</html>
Re: Create A Clock With Javascript
I have created the script below for getting clock in javascript. You canmake use of it.
Code:
<script type="text/javascript">
<!--
function updateClock ( )
{
var currt = new Date ( );
var currh = currt.getHours ( );
var currm= currt.getMinutes ( );
var currs = currt.getSeconds ( );
currm= ( currm< 10 ? "0" : "" ) + currm;
currs = ( currs < 10 ? "0" : "" ) + currs;
var timeOfDay = ( currh < 12 ) ? "AM" : "PM";
currh = ( currh > 12 ) ? currh - 12 : currh;
currh = ( currh == 0 ) ? 12 : currh;
var currtString = currh + ":" + currm+ ":" + currs + " " + timeOfDay;
document.getElementById("clock").firstChild.nodeValue = currtString;
}
// -->
</script>
Re: Create A Clock With Javascript
Use the methods below to create your Javascript for getting the clock:
- getDate() - For returning day of month
- getDay() - For returning day of week
- getHours() - For returning hour
- getMinutes() - For returning minutes
- getSeconds() - For returning seconds
- getMonth() - For returning month
- getYear() - For returning year
- getTime() - For returning complete time
Re: Create A Clock With Javascript
You need to make use of the list below for javascript reference:
- JavaScript Programmer's Reference
- Teach Yourself JavaScript In A Week
- Using JavaScript Special Edition
- JavaScript For The World Wide Web 2
- Instant JavaScript
I always use JavaScript Programmer's Reference for my reference.