Javascript 如何为解析时刻日期添加小时数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43407338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:54:25  来源:igfitidea点击:

How to add hours to a parse moment date?

javascriptmomentjs

提问by Arnold wanna be

I just want to ask if it is possible to add hours to a parse moment date. I have a code like this:

我只是想问是否可以在解析时刻日期中添加小时数。我有一个这样的代码:

var myDate = "2017-04-14 07:07:15"; 
var object_myDate = moment(myDate).format('YYYY-MM-DD hh:mm:ss');
var status = object_myDate.add(5, 'hours');

but this code gives the following error:

但此代码给出了以下错误:

object_myDate.add is not a function
object_myDate.add is not a function

回答by VincenzoC

addis a moment function, you should use on moment object:

add是一个矩函数,你应该在矩对象上使用:

var myDate = "2017-04-14 07:07:15"; 
var status = moment(myDate).add(5, 'hours').format('YYYY-MM-DD hh:mm:ss');