A Pen by Cole Roberts

Thumbnail
This awesome code was written by colealanroberts, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright colealanroberts ©

Technologies

  • HTML
  • CSS
  • JavaScript
    <button id="save">Save</button>
<span id="relative-time"></span>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.js"></script>

/*Downloaded from https://www.codeseek.co/colealanroberts/a-pen-by-cole-roberts-VLvpzR */
    


/*Downloaded from https://www.codeseek.co/colealanroberts/a-pen-by-cole-roberts-VLvpzR */
    (function() {
  // HTML Elements
	var $btn = document.getElementById('save');
  var $relTime = document.getElementById('relative-time');  
  
  var tObj = {};
  var now = moment();
  var t = now.format("dddd, MMMM Do YYYY, h:mm:ss a");
   
  function saveObj() {
  	tObj = {
      timeClicked: now
    }
    console.log(tObj.timeClicked);
    
    setInterval(function() {
      var rel = tObj.timeClicked.fromNow(true);
      console.log(rel);
    }, 1000);
  }
  
  $btn.addEventListener('click', saveObj);
})();

Comments