Moment.js "Invalid date" Moment.js "Invalid date" jquery jquery

Moment.js "Invalid date"


Suppose your date is in format 'DD-MM-YYYY' & you want to display it in DD-MMM format then you can do this by first telling moment function which format your date currently is & then asking it to convert it to required format. Below is the example:

var taskDueDate = moment(dueDate, 'DD-MM-YYYY').format('DD-MMM');

This way you can convert your date in any format.


Change the format of the datepicker to:

$("#h_reg_date").datepicker("option", "dateFormat", "yy/mm/dd");

JS Fiddle: http://jsfiddle.net/MMm86/1/

To put the date in your requested format use:

$( "#h_reg_date" ).datepicker();$("#h_reg_date").datepicker("option", "dateFormat", "yy/M/dd");$("#save_data").on("click", function(){ var reg_date = $("#h_reg_date").val();  console.log(reg_date);  reg_date =  moment(reg_date).format("YYYY/MMM/DD");  console.log(reg_date);  return;});

JS Fiddle: http://jsfiddle.net/MMm86/2/


It seems to be a known issue, per their docs.http://momentjs.com/docs/#/parsing/string/

Looks like they suggest passing in the time string and the format.