问题
My code :
$('#datepicker').datepicker({
inline: true,
onSelect: function(dateText, inst) {
var d = new Date(dateText);
alert("DateText=>"+ dateText + "," + "DATE =>" + d);
$('#calendar').fullCalendar('gotoDate', d);
}
});
})
My error :

My problem is that the function is being passed dateText from fullCalendar in the form dd/mm/yyyy...it is then creating a new date using this and it is messing it up, thinking that the date should be in the form mm/dd/yy. Can anyone help me fix this please?
回答1:
You are alerting the dateText but passing a date object to calendar. Look at FullCalendar API for format of 'gotDate' argument. You can use
d.getFullYear(), d.getMonth() and d.getDate() to convert
回答2:
Try this,may be it will little helpfull for you
var date = $('#datepicker').datepicker({ dateFormat: 'mm-dd-yy' });
回答3:
If you're looking to format the date. Try date format
edit: maybe your date variable is wrong. Try
<div id="datepicker"></div>
var date = $('#datepicker').datepicker('getDate');
$.datepicker.formatDate('mm-dd-yy', date);
来源:https://stackoverflow.com/questions/9506220/date-is-interpreted-as-being-in-a-different-format