我有一个运作良好的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?
答案 0 :(得分:8)
var today = moment();
var startDate = '2015-05-06T19:00:00+0300';
moment(startDate).isBetween(today, moment(today).add(30, 'days'));
您通过添加30天来传递已编辑的参考。