Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function timeAgo(num_seconds) {
  2. function numberEnding (number) {
  3. return (number > 1) ? 's ago' : ' ago';
  4. }
  5. if (num_seconds <= 0) {
  6. return 'just now!';
  7. }
  8. var years = Math.floor(num_seconds / 31536000);
  9. if (years) {
  10. return years + ' yr' + numberEnding(years);
  11. }
  12. var days = Math.floor((num_seconds %= 31536000) / 86400);
  13. if (days) {
  14. return days + ' day' + numberEnding(days);
  15. }
  16. var hours = Math.floor((num_seconds %= 86400) / 3600);
  17. if (hours) {
  18. return hours + ' hr' + numberEnding(hours);
  19. }
  20. var minutes = Math.floor((num_seconds %= 3600) / 60);
  21. if (minutes) {
  22. return minutes + ' min' + numberEnding(minutes);
  23. }
  24. if (num_seconds < 60) {
  25. return num_seconds + ' sec' + numberEnding(num_seconds);
  26. }
  27. return 'just now!';
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement