I have a timestamp ing from a table in utc like: 2018-02-21 23:31:49.391
I'm confident it's UTC time so I make a moment out of it.
let exp = moment(2018-02-21 23:31:49.391);
That represents an expiration date/time. I'm trying to use moment to check if that timestamp is in the past pared to the current time. I think part of my issue is that perhaps moment doesn't know that's in UTC. If so, how can i specify in the constructor?
To do this parison/validation I'm creating a new moment like let now = moment().utc();
and then paring the time like
now.isAfter(exp)
However, it keeps ing back as false for me. Is not specifying the first timestamp as UTC the issue?
I have a timestamp ing from a table in utc like: 2018-02-21 23:31:49.391
I'm confident it's UTC time so I make a moment out of it.
let exp = moment(2018-02-21 23:31:49.391);
That represents an expiration date/time. I'm trying to use moment to check if that timestamp is in the past pared to the current time. I think part of my issue is that perhaps moment doesn't know that's in UTC. If so, how can i specify in the constructor?
To do this parison/validation I'm creating a new moment like let now = moment().utc();
and then paring the time like
now.isAfter(exp)
However, it keeps ing back as false for me. Is not specifying the first timestamp as UTC the issue?
Share Improve this question asked Feb 21, 2018 at 23:47 sb9sb9 3161 gold badge8 silver badges22 bronze badges 1- Please include a Minimal, Complete, and Verifiable example of your code so we can more easily understand the problem. – Herohtar Commented Feb 21, 2018 at 23:56
2 Answers
Reset to default 4Try it:
var a = moment('2018-02-21 23:31:49.391');
var b = moment().utc();
var d = a.diff(b,'days');
if (d > 0){
//a is bigger than b actual moment.
} else if (d < 0){
//a is smaller than b actual moment.
}else{
//a = b
}
If it's UTC time, then
let exp = moment.utc('2018-02-21 23:31:49.391');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742315662a4420786.html
评论列表(0条)