Date is interpreted as being in a different format

时间秒杀一切 提交于 2019-12-25 03:21:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!