我从 MongoDB 获得了创建时间,我想为此添加 6 小时。如果现在时间少于创建时间添加 6 小时后,我想要一个可见的按钮。我使用 moment.js
timenow:moment().format('LT')
{this.state.timenow > moment(post.createdAt).format('LT') &&
<Button
variant="outline-info"
className="cardbutton"
size="sm"
onClick={this.editPost.bind(this, post._id, post.message)}
>
Edit
</Button>}
最佳答案
您可以使用:
moment(time).add(x, 'hours')
其中 time
是您想要偏移 x 小时的时间对象
关于javascript - 如何偏移 moment.js 时间对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66771461/