开发者

Javascript date comparison issues with datejs

I have a date object, but the isAfter function in the API of datejs is not working. I opened the js library and cannot find any mention of it in there. I downloaded the latest version from dateJS site. Can anyone advise? Is there another method I should be using?

I am basically trying to compare a date to the current date, and see if it is less than 1 min before, less than 1hr before, less than 1 day before etc.

My code is:

function GetCleverDateString(date) {

    // Just a moment ago <1 min
    // X minutes ago
    // X hours ago
    // Yesterday
    alert(date.toString()); // date is constructed via new Date(...); this alerts the full date string 

    var theDate = new Date(date.toString()); // was experimenting

    if (theDate.isAfter(Date.today().addMinutes(-1)))
    {
        return 'Just now';
    }

    if (theDate.isAft开发者_运维技巧er(Date.today().addHours(-1)))
    {
        return 'Less than an hour ago';
    }


}

I notice the version in their SVN has these methods. Perhaps I can get that? I don't know how though.


Okay turns out that the API doesn't match up to the actual JS on the download at all. You have to go to this url to get the latest version:

http://code.google.com/p/datejs/source/browse/trunk/#trunk%2Fbuild

Click the file you want

Then right click 'view raw file' and save as. This is the latest version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜