date.getTime is not a function

2019-08-17 18:42发布

问题:

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
        }   
    });
}

回答1:

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());
}   


回答2:

Try to convert date into date object hope it works

dayRender: function (date, cell) {
    dateObj =new Date(date);
    console.log(date.getDate());
}