$.each(data[i].replies, function(m, n) {
var currentdate = new Date();
console.log(n.entry.date_entered);
check = moment(n.entry.date_entered, 'YYYY/MM/DD');
check1 = moment(currentdate, 'YYYY/MM/DD');
console.log(check);
console.log(check1);
var month = check.format('M');
var day = check.format('DD');
var year = check.format('YYYY');
var month1 = check1.format('M');
var day1 = check1.format('DD');
var year1 = check1.format('YYYY');
get = moment([year, month, day]);
get1 = moment([year1, month1, day1]);
g = get1.from(get);
});
示例 n.entry.date_entered
:2014-07-28 12:23:43
对于我几秒钟前收到的所有日期,不知道为什么
最佳答案
我认为您的问题是您传递给moment
的格式掩码。
在示例中,您使用 -
作为分隔符,但在格式掩码中,您使用 /
。这样 moment
将无法解析日期,而是为您提供当前日期。
尝试将格式掩码更改为“YYYY-MM-DD”
。
关于javascript - X 的时间未按预期工作 moment.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25029500/