开发者

Date.JS parse isBefore problem

Im using date.js to compare to dates that are written in user friendly string form(Sat, 1 July 2006 12:34:14). I use this code.

function is_new(lasttime, newtime){
    lasttime = Date.parse(lastime);
    newtime = Date.parse(newtime);
    if(lasttime.isBefore(newtime)){
        return true;
    }else{
        return false;
    }
}

Both lasttime and newtime are str开发者_开发百科ings like above. When I try this i get

Uncaught TypeError: Object Tue Dec 30 1997 00:00:00 GMT+0000 (GMT Standard Time) has no method 'isBefore'


There's no function named isBefore. Instead, compare the timestamps:

function is_new(LastTime,NewTime){
  return new Date(LastTime).getTime()<new Date(NewTime).getTime();
}

alert(is_new("Dec 30, 1997","Dec 31, 1997"));


Actually there is that function in the newer release. Just check out the source code at http://www.datejs.com/ or download date.js file here http://www.datejs.com/build/date.js. It worked for me.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜