Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  Last run: <span id="time"></span><br>
  Next execution: <span id="target"></span>
    <script type="text/javascript">
        function executeMe(){
          alert("9 seconds!");
        }
        var timeout = null;
        var interval = null;
        function timer(){
          var now = new Date();
          document.getElementById('time').innerHTML = now;
          document.getElementById('target').innerHTML = new Date(now.getTime()+ 1000);
          //console.log("timer()", now);
          
          if(now.getSeconds() == 9)
            setTimeout("executeMe();",1); // async
          
          if(interval == null)
            interval = setInterval("timer()",1000);
        }
    
        var now = new Date();
        var target = new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),now.getSeconds()+1,0);
        //console.log("now", now);
        //console.log("target", target);
        //console.log("diff", target.getTime() - now.getTime());
        document.getElementById('target').innerHTML = target;
        timeout = setTimeout("timer()", target.getTime() - now.getTime() );
      </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers