SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
     
    <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>

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Welcome to the forums

    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"?

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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" 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>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •