Created
July 15, 2012 03:24
-
-
Save msroot/3114765 to your computer and use it in GitHub Desktop.
time ago with now.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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