javascript - momentjs for checking expired timestamp - Stack Overflow

I have a timestamp ing from a table in utc like: 2018-02-21 23:31:49.391 I'm confident it's U

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
Add a ment  | 

2 Answers 2

Reset to default 4

Try 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

相关推荐

  • javascript - momentjs for checking expired timestamp - Stack Overflow

    I have a timestamp ing from a table in utc like: 2018-02-21 23:31:49.391 I'm confident it's U

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信