moment.js - isBetween()方法不能始终如一地工作

时间:2015-05-02 09:35:33

标签: javascript node.js date momentjs

我有一个运作良好的moment.js代码:

var startDate = '2015-05-06T19:00:00+0300';
moment(startDate).isBetween(moment(), moment().add(30, 'days'));
// returns true, that's great!

但是当我开始重构以使其更具可读性时,它无法工作:

var today = moment();
var startDate = '2015-05-06T19:00:00+0300'; 
moment(startDate).isBetween(today, today.add(30, 'days'));
// returns false.. but why?

1 个答案:

答案 0 :(得分:8)

var today = moment();
var startDate = '2015-05-06T19:00:00+0300'; 
moment(startDate).isBetween(today, moment(today).add(30, 'days')); 

您通过添加30天来传递已编辑的参考。