[英]Moment.js convert MM/dd/yyyy format date
当用户输入MM / dd / yyyy格式的数据时,我有文本框,然后我需要解析该数据并将其转换为日期。 我使用了momentjs,但是我的代码无法正常工作。 这是我的代码段。
var otherProp = $('#' + param.otherproperty);
var StartDate = new date(moment(otherProp.val(), 'MM/dd/yyyy'));
特别是这行不工作var StartDate = new date(moment(otherProp.val(), 'MM/dd/yyyy'));
我在哪里弄错了? 谢谢
我的完整代码如下
$.validator.addMethod("isgreater", function (value, element, param) {
var otherProp = $('#' + param.otherproperty);
var StartDate = new Date(moment(otherProp.val(), 'MM/DD/YYYY'));
var Enddate = new Date(value);
if (StartDate != '')
{
return Enddate >= StartDate;
}
return false;
});
将所有MM/dd/yyyy
为大写MM/DD/YYYY
所以这应该工作
var otherProp = $('#' + param.otherproperty);
var StartDate = new Date(moment(otherProp.val(), 'MM/DD/YYYY'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.