开发者

Date.JS parse isBefore problem

开发者 https://www.devze.com 2023-01-04 05:39 出处:网络
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.

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

精彩评论

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

关注公众号