首页 文章

将日期1和日期2与10分钟进行比较

提问于
浏览
0

这是我计算持续时间的方式:

var duration = new Date().getTime() - customerForgotPassword[0].createdTime.getTime();

这是我比较的方式:

var TEN_MINUTES = 10*60*1000;

if(duration > TEN_MINUTES){
//do smtg
}

new Date().getTime() 返回 1528291351108 ,这是UTC中的 Wed Jun 06 2018 13:22:31

customerForgotPassword[0].createdTime 在我的代码中返回 Wed Jun 06 2018 13:20:04 GMT+0800 (Malay Peninsula Standard Time) .

customerForgotPassword[0].createdTime.getTime() 返回 1528262404000 ,这是UTC中的 Wed Jun 06 2018 05:20:04

在数据库中, customerForgotPassword[0].createdTimeUTC format 中,但是当我检索它时,它显示本地时区 . 当我使用Sequelize在node.js中检索它时,如何将其设置为UTC格式?

1 回答

  • 0

    我不得不增加8小时来获得UTC时间

    var timeInUTC = customerForgotPassword[0].createdTime.getTime() - (customerForgotPassword[0].createdTime.getTimezoneOffset() * 60 * 1000)
    

相关问题