admin管理员组文章数量:1332353
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');
本文标签: javascriptmomentjs for checking expired timestampStack Overflow
版权声明:本文标题:javascript - momentjs for checking expired timestamp - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315662a2451764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论