Moment.js "Invalid date"
datepicker, jquery, momentjs
Solution
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/
Problem
I just tried to make a text input with formatted date. It is working fine on Google Chrome, but when I run it on Mozilla Firefox (26.0) it says: `Invalid date`. You can see and run my example in both browsers and hopefully understand the problem. JS Code: ``` $( "#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/MM/DD"); console.log(reg_date); return; }); ``` HTML: ``` <input type="text" id="h_reg_date"class="abs" style="top:135px; left:150px;" size="10" readonly > <input type="button" id="save_data" class="abs" style="top:370px; left:-200px;" value="Add Data"> ``` Is there any solution to this problem?