Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timeAgo(num_seconds) {
- function numberEnding (number) {
- return (number > 1) ? 's ago' : ' ago';
- }
- if (num_seconds <= 0) {
- return 'just now!';
- }
- var years = Math.floor(num_seconds / 31536000);
- if (years) {
- return years + ' yr' + numberEnding(years);
- }
- var days = Math.floor((num_seconds %= 31536000) / 86400);
- if (days) {
- return days + ' day' + numberEnding(days);
- }
- var hours = Math.floor((num_seconds %= 86400) / 3600);
- if (hours) {
- return hours + ' hr' + numberEnding(hours);
- }
- var minutes = Math.floor((num_seconds %= 3600) / 60);
- if (minutes) {
- return minutes + ' min' + numberEnding(minutes);
- }
- if (num_seconds < 60) {
- return num_seconds + ' sec' + numberEnding(num_seconds);
- }
- return 'just now!';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement