我试图弄清楚两个dates之间的区别,但我得到的回应是:在我见过的其他主题上,我必须创建一个moment对象,但据我所知,我正在这样做。代码:
function datecheck(){
var y = moment($("#input_pickup_date").val(),"L").format("L");
var x = moment().format("L");
console.log(x.diff(y, 'days'));
}
发布于 2018-08-30 08:43:36
通过docs,moment().format()
返回一个字符串,所以你的x
和y
变量都是字符串。如果您需要同时计算和显示值,请将它们分离到不同的变量中:
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'));
}
https://stackoverflow.com/questions/52086695
复制相似问题