时刻.js转换 MM/dd/yyyy 格式日期

Moment.js convert MM/dd/yyyy format date

本文关键字:yyyy 格式 日期 dd 时刻 转换 MM js      更新时间:2023-09-26
当用户

以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'));