Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
timeSince<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
  <p id="hello" class="timeSince">Hello World</p>
  <hr>
  <div id="counter"></div>
</body>
</html>
 
        var startTime = new Date() / 1000;
        $(document).ready(function () {
            setTimeout(updateClock, 1000);
        });
        function updateClock() {
            var timeField = $(".timeSince");
            var currentTime = new Date();
            var difference =   currentTime- startTime;
            timeField.html(MillisecondsToDuration(difference));
            setTimeout(updateClock, 1000);
        }
        function MillisecondsToDuration(n) {                 
            var hms = "";                    
            var dtm = new Date();                 
            dtm.setTime(n);              
            var h = "000" + Math.floor(n / 3600000);     
          
            var m = "0" + dtm.getMinutes();         
            var s = "0" + dtm.getSeconds();        
            hms = h.substr(h.length-4) + " hours, " + m.substr(m.length-2) + " mins, ";                
            hms += s.substr(s.length-2) + " secs";
            return hms;              
        } 
var DATE1 = new Date(1389775451)/1000; 
var DATE2 = (new Date).getTime(); 
var START_DATE = DATE2 - DATE1; // put in the starting date here
var INTERVAL = 1; // in seconds
var INCREMENT = 1; // increase per tick
var START_VALUE = 9001; // initial value when it's the start date
var count = 0;
window.onload = function()
{
 var msInterval = INTERVAL * 1000;
 var now = new Date();
 count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
 document.getElementById('counter').innerHTML = count;
 setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = count;", msInterval);
}
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers