首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >.diff不是Moment.js中的函数

.diff不是Moment.js中的函数
EN

Stack Overflow用户
提问于 2018-08-30 06:04:47
回答 1查看 2.7K关注 0票数 0

我试图弄清楚两个dates之间的区别,但我得到的回应是:在我见过的其他主题上,我必须创建一个moment对象,但据我所知,我正在这样做。代码:

代码语言:javascript
复制
function datecheck(){
  var y = moment($("#input_pickup_date").val(),"L").format("L");
  var x = moment().format("L");
  console.log(x.diff(y, 'days'));
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-30 08:43:36

通过docsmoment().format()返回一个字符串,所以你的xy变量都是字符串。如果您需要同时计算和显示值,请将它们分离到不同的变量中:

代码语言:javascript
复制
function datecheck() {
    var dateSubmitted = moment($("#input_pickup_date").val(), "L"), //your old x variable
        now = moment(), //your old y variable
        dateSubmittedDisplay = dateSubmitted.format("L"), //a string representing the submitted date in the format you wanted.
        nowDisplay = now.format("L"); //a string representing now in the format you wanted.

    console.log(x.diff(y, 'days'));
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52086695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档