[英].diff is not a function in Moment.js
我试图获取两个日期之间的差额,但得到响应: Uncaught TypeError: x.diff is not a function
在其他主题上,我已经看到我必须创建一个矩对象,但到目前为止我知道,我正在这样做。 码:
function datecheck(){
var y = moment($("#input_pickup_date").val(),"L").format("L");
var x = moment().format("L");
console.log(x.diff(y, 'days'));
}
通过docs , moment().format()
返回一个String,因此您的x
和y
变量均为String。 如果您既需要进行计算并显示值,则将它们分成不同的变量:
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'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.