Skip to content

Instantly share code, notes, and snippets.

@pypetey
Created June 27, 2014 08:16
Show Gist options
  • Save pypetey/724774df3fc4d3388e3c to your computer and use it in GitHub Desktop.
Save pypetey/724774df3fc4d3388e3c to your computer and use it in GitHub Desktop.
Periodically update time when element was added with moment.js
<script type="text/javascript">
$(document).ready(function() {
var update = function() {
$('time').each(function() {
date = moment(new Date($(this).attr("datetime")));
$(this).html(date.fromNow());
});
};
update();
setInterval(update, 1000 * 60);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment