Javascript 如何偏移moment.js时间对象

Javascript 如何偏移moment.js时间对象,javascript,reactjs,momentjs,Javascript,Reactjs,Momentjs,我从MongoDB获得了创建时间,我想为此增加6个小时。我想要一个可见的按钮,如果现在的时间少于之后添加6小时的创建时间。我使用moment.js timenow:moment().format('LT') {this.state.timenow>moment(post.createdAt.format('LT'))&& 编辑 } 您可以使用: moment(time)。添加(x,'hours')其中time是您要用x小时来抵消的时间对象。谢谢您,很高兴我能提供帮助。 {this.state.

我从MongoDB获得了创建时间,我想为此增加6个小时。我想要一个可见的按钮,如果现在的时间少于之后添加6小时的创建时间。我使用
moment.js

timenow:moment().format('LT')
{this.state.timenow>moment(post.createdAt.format('LT'))&&
编辑
}
您可以使用:
moment(time)。添加(x,'hours')
其中
time
是您要用x小时来抵消的时间对象。谢谢您,很高兴我能提供帮助。
{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>}