在给定的unix时间戳中添加小时x

问题描述

我有以下使用moment的函数,该函数检查与给定的UNIX时间戳之间以分钟为单位的差异。 actualStartTime is in unix format (for e.g 1599226113699)

const endTime = moment(offer.data.actualStartTime,"x")
  if (endTime.diff(now,"minutes") <= 15 && snapshot.key) {
    remindersSentKeys.push(snapshot.key)
}

Unix时间戳存储在offer.data.actualStartTime中。我的问题是我需要添加另一个字段duration: number,该字段在endTime变量中添加小时数,并以时间格式返回。

const finalEndTime = moment(offer.data.actualStartTime,"x") + *offer.data.duration*

例如duration is 4。变量finalEndTime应该在actualStartTime中再加上4个小时,然后检查15分钟的差异。

解决方法

这将使现有时间增加duration小时

moment().add({hours: duration})

根据您的情况

const finalEndTime = moment(offer.data.actualStartTime,"x").add({hours: offer.data.duration});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...