2

私は、date.js を使用して、ユーザー フレンドリーな文字列形式 (2006 年 7 月 1 日 12:34:14) で記述された日付と比較しています。私はこのコードを使用します。

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

lasttime と newtime はどちらも上記のような文字列です。これを試すと、

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

2 に答える 2

1

isBefore という名前の関数はありません。代わりに、タイムスタンプを比較します。

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

alert(is_new("Dec 30, 1997","Dec 31, 1997"));
于 2010-06-19T19:26:50.547 に答える