|
||||||
| JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello..alls
I am new in java script, I am making a application . in which i need to make a java script clock which count time ....I am trying to understand you it in more detail After successfull user login clock show at top corner and it start from 00:00:00 and now it start time counting . Can any one help he how can i do this |
| Sponsored Links |
|
|
|
|||||
|
Quote:
to make Countdown in javascript we need to work with Timers and setTimes. this is a simple countdown script, watch it carefully to know how it works Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Countdown</title>
</head>
<body onload="timer()">
<style type="text/css">
#time{
font-size:50pt;
}
</style>
<script type="text/javascript">
i=90;
function timer()
{
document.getElementById('time').innerHTML = i+1;
setTimeout('timer()', 1000); //this will make loop this function for every one second
i--;
}
</script>
<div id="time">90</div>
</body>
</html>
if you to make the countdown FASTER, you can replace 1000 value with 500 for example. to stop a javascript timer we will use ClearTIMER which i don't think you need it...
__________________
my free software and games |
|
|||||
|
and i now i changed the above code to make a
digital clock with this format "00:00:00" Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Digitl clock</title>
</head>
<body onload="timer()">
<style type="text/css">
#time{
font-size:50pt;
}
</style>
<script type="text/javascript">
var digiclock = "00:00:00";
i = 0;
function timer()
{
var digiformat = "";
if(i>3599)
{
var H = Math.floor(i/3600);
}
else
{
var H = 0;
}
var M = i - (H*3600)
if(M>59)
{
M = Math.floor(M/60)
}
else
{
M = 0
}
var S = i - (M*60)
if(H<10)
{
H = "0"+H;
}
if(M<10)
{
M = "0"+M;
}
if(S<10)
{
S = "0"+S;
}
document.getElementById('time').innerHTML = H+":"+M+":"+S;
setTimeout('timer()', 1000);
i++;
}
</script>
<div id="time">90</div>
</body>
</html>
__________________
my free software and games |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Javascript: Analog Clock | TcM | Javascript | 20 | 05-28-2008 09:01 AM |
| WHAT is wrong with WHICH clock in my machine? | tymoty | General Programming | 2 | 11-01-2007 10:59 PM |
| Creating an analog clock with ActionScript | AfTriX | Tutorials, Classes and Code | 2 | 01-07-2007 02:19 AM |
| Counter | Blaze | General Programming | 1 | 08-22-2006 06:24 AM |