Skip to content

Instantly share code, notes, and snippets.

@msroot
Created July 15, 2012 03:24
Show Gist options
  • Select an option

  • Save msroot/3114765 to your computer and use it in GitHub Desktop.

Select an option

Save msroot/3114765 to your computer and use it in GitHub Desktop.
time ago with now.js
<head>
</head>
<body>
<time class="time_ago" data-date="1342319482"></time>
<time class="time_ago" data-date="1334381474"></time>
<script src="http://localhost:3030/javascripts/jquery.js?1333364529"></script>
<script src="https://raw.github.com/timrwood/moment/1.6.2/moment.js"></script>
<script>
$(document).ready(function(){
function update_time_ago(){
$(".time_ago").each(function () {
var time_ago = $(this),
date = moment.unix(time_ago.attr('data-date'));
time_ago.html(date.fromNow());
});
};
update_time_ago();
setInterval(update_time_ago, 6000);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment