Count up script from a given date

Hey good people on this forum

I’m in need for a count up script that counts from a specific date since the last incident. I got a fairly easy script working but I need a function that reset the date or if possible, set the date manually directly from the webpage. Is this possible? Here is the script im using right now.


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#timer {
    width:430px;
    line-height:40px;
    border:3px double #999;
    font-family:verdana,arial,helvetica,sans-serif;
    font-size:1em;
    text-align:center;
    margin:40px auto;
 }
</style>

<script type="text/javascript">
window.onload=function() {
   doTime();
 }
function doTime() {

   now=new Date ();
   then=new Date ('feb,06,2014,22:31:00');

   difference=(now-then);

   days=Math.floor(difference/(60*60*1000*24)*1);
   hours=Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
   mins=Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
   secs=Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);

   document.getElementById('timer').firstChild.nodeValue=

     'Det er nå '+days+' dager '+hours+' timer '+mins+' minutter '+secs+' sekunder siden siste beredskapshendelse';

   setTimeout('doTime()',1000);
 }
</script>
</head>

<body>

 <div id="timer">&nbsp;</div>

</body>
</html>



Hi,

Welcome to the forums :slight_smile:

Can you elaborate on what you mean by “a function that reset the date or if possible, set the date manually directly from the webpage”?

<!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" xml:lang="en" lang="en">

<head>
  <title></title>
</head>

<body>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#timer {
    width:430px;
    line-height:40px;
    border:3px double #999;
    font-family:verdana,arial,helvetica,sans-serif;
    font-size:1em;
    text-align:center;
    margin:40px auto;
 }
</style>

<script type="text/javascript">
window.onload=function() {
   doTime('feb,06,2014,22:31:00');
 }
function doTime(then) {

   now=new Date ();
   then=new Date (then);

   difference=(now-then);

   days=Math.floor(difference/(60*60*1000*24)*1);
   hours=Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
   mins=Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
   secs=Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);

   document.getElementById('timer').firstChild.nodeValue=

     'Det er nå '+days+' dager '+hours+' timer '+mins+' minutter '+secs+' sekunder siden siste beredskapshendelse';
   clearTimeout(doTime.to);
   doTime.to=setTimeout(function(){ doTime(then); },1000);
 }
</script>
</head>

<body>

 <div id="timer">&nbsp;</div>
<input type="button" name="" value="Set Date" onmouseup="doTime('feb,16,2014,22:31:00');" />
</body>
</html>
</body>

</html>