日期被解释为采用不同的格式
我的代码:
$('#datepicker').datepicker({ inline: true, onSelect: function(dateText, inst) { var d = new Date(dateText); alert("DateText=>"+ dateText + "," + "DATE =>" + d); $('#calendar').fullCalendar('gotoDate', d); } }); })
我的错误:
我的问题是该函数正在从fullCalendar以dd / mm / yyyy的forms传递dateText …然后使用它创建一个新日期并且它正在搞乱它,认为日期应该是mm / DD / YY。 有人可以帮我解决这个问题吗?
您正在警告dateText,但将日期对象传递给日历。 查看FullCalendar API以获取’gotDate’参数的格式。 您可以使用
d.getFullYear(), d.getMonth() and d.getDate() to convert
试试这个,可能对你没什么帮助
var date = $('#datepicker').datepicker({ dateFormat: 'mm-dd-yy' });
如果您要格式化日期。 尝试日期格式
编辑:也许你的日期变量是错误的。 尝试
var date = $('#datepicker').datepicker('getDate'); $.datepicker.formatDate('mm-dd-yy', date);