Correct Time Display

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2010-05-11T21:41:57Z Indexed on 2010/05/11 21:44 UTC
Read the original article Hit count: 285

Filed under:
|
|

Guys,

I''m looking to get this correct and i'm getting a bit fustrated with this. What I want to do is get hours and days and weeks correct.

Example: if this post is < 60min old then have it read: Posted Less then 1 minute ago if this post is < 120min old then have it read: Posted 1 hour ago if this post is > 120min old then have it read: Posted 1 hours ago if this post is < 1440min old then have it read: Posted 1 day ago if this post is > 1440min old then have it read: Posted 2 days ago

Is that right??

This is what I have so far:

if (lapsedTime < 60) {
        return '< 1 mimute';
    } else if (lapsedTime < (60*60)) {
        return Math.round(lapsedTime / 60) + 'minutes';
    } else if (lapsedTime < (12*60*60)) {
        return Math.round(lapsedTime / 2400) + 'hr';
    } else if (lapsedTime < (24*60*60)) {
        return Math.round(lapsedTime / 3600) + 'hrs';
    } else if (lapsedTime < (7*24*60*60)) {
        return Math.round(lapsedTime / 86400) + 'days';
    } else {
        return Math.round(lapsedTime / 604800) + 'weeks';
    }

© Stack Overflow or respective owner

Related posts about time

Related posts about datetime