简体   繁体   中英

Moment.js convert MM/dd/yyyy format date

i have textbox when user enter data with MM/dd/yyyy format then i need to parse that data and convert it to date. i used momentjs but my code not working. here is my code snippet.

var otherProp = $('#' + param.otherproperty);
var StartDate = new date(moment(otherProp.val(), 'MM/dd/yyyy'));

specially this line is not working var StartDate = new date(moment(otherProp.val(), 'MM/dd/yyyy')); where i made the mistake ? thanks

UPDATE

my full code as follows

$.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;
});

convert all of the MM/dd/yyyy to uppercase MM/DD/YYYY

so this should work

var otherProp = $('#' + param.otherproperty);
var StartDate = new Date(moment(otherProp.val(), 'MM/DD/YYYY'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM