I'm using moment.js to format my date time, here I have two date values, and I want to achieve a particular function when one date is greater than the other.
(我正在使用moment.js格式化日期时间,这里有两个日期值,当一个日期大于另一个日期时,我想实现一种特定的功能。)
I read most of their docs, but didn't find the function to achieve this.(我阅读了他们的大多数文档,但没有找到实现此功能的功能。)
I know it will be there.(我知道会在那里。)
This is my code:
(这是我的代码:)
var date_time = 2013-03-24 + 'T' + 10:15:20:12 + 'Z'
var d = moment(date_time).tz('UTC'); // first date
var now = new Date(),
dnow = moment(now).tz('UTC'),
snow = dnow.minute() % 15,
diffnow = 15 - snow,
tonow = moment(dnow).add('minute', diffnow),
ahead30now = moment(tonow).add('minute', 30);
if (d > ahead30now) {
// allow input time
console.log('UTC TIME DB', d.format());
} else {
}
Edit
(编辑)
var date_time = req.body.date + 'T' + req.body.time + req.body.timezone; // 2014-03-24T01:15:000
var utc_input_time = moment(date_time).utc(); // 2014-03-24T01:15:000
console.log('utc converted date_time', moment(date_time).utc().format("YYYY-MM-DDTHH:mm:SSS"));
var isafter = moment(utc_input_time).isAfter(moment('2014-03-24T01:14:000')); // true
if(isafter === true){
console.log('is after true');
} else {
console.log('is after is false');
}
Here, I am comparing two dates ie 2014-03-24T01:15:000 > 2014-03-24T01:14:000
, expecting that the first one is greater than the second one, but it always goes to the else condition.
(在这里,我正在比较两个日期,即2014-03-24T01:15:000 > 2014-03-24T01:14:000
,期望第一个日期大于第二个日期,但是它总是转到else条件。)
I don't know why?(不知道为什么)
ask by Dibish translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…