Předchozí Index Další

Čas od stisknutí tlačítka

Ukázka DownLoad



<html>
<head>
<title>
JavaScript
</title>
<script language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;
var logTime = false;
var logSeconds = 0;
var logMinutes = 0;
var logHours = 0;
var stopHours = 0;
var stopMinutes = 0;
var stopSeconds = 0;
var startHours = 0;
var startMinutes = 0;
var startSeconds = 0;
var newSeconds = 0;
var newMinutes = 0;
var newHours = 0;
var reset = false;
function Reset()
{
logTime = false;
logSeconds = 0;
logMinutes = 0;
logHours = 0;
stopHours = 0;
stopMinutes = 0;
stopSeconds = 0;
startHours = 0;
startMinutes = 0;
startSeconds = 0;
newSeconds = 0;
newMinutes = 0;
newHours = 0;
reset = true;
stopclock();
}

function UpdateTimerOnStart()
{
var now = new Date();
if (reset == true)
{
stopHours = now.getHours();
stopMinutes = now.getMinutes();
stopSeconds = now.getSeconds();
reset = false;
}
startHours = now.getHours();
startMinutes = now.getMinutes();
startSeconds = now.getSeconds();
if (startSeconds >= stopSeconds)
{
newSeconds = startSeconds - stopSeconds;
}
else
{
startMinutes -= 1;
newSeconds = (startSeconds + 60) - stopSeconds;
}
if (startMinutes >= stopMinutes)
{
newMinutes = startMinutes - stopMinutes;
}
else
{
startHours -= 1;
newMinutes = (startMinutes + 60) - stopMinutes;
}
newHours = startHours - stopHours;
logSeconds = newSeconds;
logMinutes = newMinutes;
logHours = newHours;
if (logSeconds >= 60)
{
logMinutes += 1;
logSeconds = 0;
}
if (logMinutes >= 60)
{
logHours += 1;
logMinutes = 0;
}
document.forms[0].elements[2].value = logHours;
document.forms[0].elements[3].value = logMinutes;
document.forms[0].elements[4].value = logSeconds;
startclock ();
}

function startclock ()
{
stopclock();
time();
}

function stopclock ()
{
if(timerRunning) clearTimeout(timerID);
timerRunning = false;
}

function time ()
{
var now = new Date();
var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
var hours = now.getHours();
hours = ((hours > 12) ? hours - 12 : hours);
var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
var timeValue =(" " + hours + minutes + seconds + " " + ampm);
document.forms[0].elements[0].value = timeValue;

if (logTime == false)
{
var logonTime =(" " + hours + minutes + seconds + " " + ampm);
stopHours = now.getHours();
stopMinutes = now.getMinutes();
stopSeconds = now.getSeconds();
document.forms[0].elements[1].value = logonTime;
}

logTime = true
logSeconds += 1;
if (logSeconds >= 60)
{
logMinutes += 1;
logSeconds = 0;
}
if (logMinutes >= 60)
{
logHours += 1;
logMinutes = 0;
}
document.forms[0].elements[2].value = logHours;
document.forms[0].elements[3].value = logMinutes;
document.forms[0].elements[4].value = logSeconds;
timerID = setTimeout("time()",1000);
timerRunning = true;
}
// -->
</script>
</head>
<BODY onLoad="Reset();" onUnload="stopclock();">
<FORM>
<TABLE BORDER=3 WIDTH=450><TR>
<TD align="center"><FONT COLOR=0000FF SIZE=+1><STRONG>Aktualny cas</STRONG></FONT><TD align="center"><FONT COLOR=0000FF SIZE=+1><STRONG>Cas prihlasenia</STRONG></FONT></TR><TR><TD align=&qu <BR>
<TABLE BORDER=3 WIDTH=450>
<TR><TD align="center"><FONT COLOR=0000FF SIZE=+1><STRONG>Hodiny</STRONG></FONT><TD align="center"><FONT COLOR=0000FF SIZE=+1><STRONG>Minuty</STRONG></FONT>
<TD align="center"><FONT COLOR=0000FF SIZE=+1><STRONG>Sekundy</STRONG></FONT>
</TR><TR><TD align="center"><INPUT TYPE="text" NAME="hours" SIZE=4 Value="--">
<TD align="center"><INPUT TYPE="text" NAME="mins" SIZE=4 Value="--">
<TD align="center"><INPUT TYPE="text" NAME="secs" SIZE=4 Value="--">
</TR></TABLE><BR>
<INPUT TYPE="button" value="Start" onClick="UpdateTimerOnStart()">
<INPUT TYPE="button" value="Pauza" onClick="stopclock()">
<INPUT TYPE="reset" value="Vynuluj" onClick="Reset()"></FORM></body>
</html>