date.getTime is not a function

2019-08-17 18:43发布

I am trying to compare some dates in javascript/jquery. But I am getting some error. What I did wrong here?

dayRender: function (date, cell) {
   console.log(date.getTime())
}   

//here am geting date.getTime is not a function

Here is my function:

 $scope.myFunction =function(balance){
    $('#fullCalendar').fullCalendar({
        defaultDate: balance.defaultDate,
        editable: true,
        eventLimit: true,           
        events: [
            {
                title: balance.title,
                start: balance.startDate                
            }
        ],

         dayRender: function (date, cell) {  // This is the callback function to modify a particular date cell.
            console.log(date.getDate());   //undefined
        }   
    });
}

2条回答
干净又极端
2楼-- · 2019-08-17 19:14

var date = new Date();
console.log(date.getDate());

Instead of passing date object everytime you call dayRender(), you can use date directly in that function.

dayRender: function (cell) {
  var date = new Date();
  console.log(date.getTime());
  console.log(date.getDate());
  console.log(date.getYear());
}   
查看更多
Root(大扎)
3楼-- · 2019-08-17 19:16

Try to convert date into date object hope it works

dayRender: function (date, cell) {
    dateObj =new Date(date);
    console.log(date.getDate());
}
查看更多
登录 后发表回答