Jump to content

[SOLVED] Counter


rugzo

Recommended Posts

Hi All,

 

i have a code which shows the clock. But i want to use it as a counter like a kronometre. It simply will start to count from zero if the page is refreshed. That i managed but i couldn't make it to count from zero.

I know that something like below

 

x = new date() ; y = new date(), start = x - y... but couldn't do it since my java knowledge is not enough. I will implement this into my php page. Can someone please help. It just has to start from 00:00:00

 

 

 

<html>

<head>

<script language="JavaScript">

 

<!--

 

 

var clockID = 0;

 

function UpdateClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

 

var tDate = new Date();

 

if((tDate.getSeconds())<=9)

{

document.theClock.theTime.value = ""

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

} else if((tDate.getMinutes())<=9) {

document.theClock.theTime.value = ""

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

} else if(((tDate.getSeconds())<=9) && ((tDate.getMinutes())<=9)) {

document.theClock.theTime.value = ""

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

} else {

 

 

document.theClock.theTime.value = ""

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

}

 

clockID = setTimeout("UpdateClock()", 1000);

}

function StartClock() {

clockID = setTimeout("UpdateClock()", 500);

}

 

function KillClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

}

 

//-->

 

</script>

</head>

<body onload="StartClock()" onunload="KillClock()">

<center>

<form name="theClock"><input name="theTime" size="8" type="text">

</form>

</center>

</body>

</html>

 

Link to comment
Share on other sites

ok i got it :)

 

<code><html>

<head>

<script language="JavaScript">

 

<!--

 

 

var clockID = 0;

var saniye = 00;

var dakika = 00;

var saat = 00;

 

function UpdateClock() {

 

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

 

saniye ++;

if(saniye <= 9)

{

var saniye_yaz = "0" + saniye ;

}else{

var saniye_yaz = saniye ;

}

 

if (saniye > 59)

{

dakika ++;

saniye = 0;

saniye_yaz ="00";

}

 

if(dakika <=9)

{

var dakika_yaz = "0" + dakika ;

}else{

var dakika_yaz = dakika ;

}

 

 

 

if(dakika > 59)

{

saat ++;

dakika = 0;

dakika_yaz = "00";

}

 

if(saat <=9)

{

var saat_yaz = "0" + saat ;

}else{

var saat_yaz = saat ;

}

 

if(saat>=24)

{

saat=0;

dakika=0;

saniye=0;

}

document.theClock.theTime.value = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

document.title = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

clockID = setTimeout("UpdateClock()", 1000);

}

 

 

function StartClock() {

clockID = setTimeout("UpdateClock()", 500);

}

 

function KillClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

}

 

//-->

 

</script>

</head>

<body onLoad="StartClock()" onUnload="KillClock()">

<center>

<form name="theClock"><input name="theTime" size="8" type="text">

</form>

</center>

</body>

</html></code>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.