Ionic 2 Calendar date argument type not assignable for createEvent()


#1

I am trying to create calendar event using my app. Basically, on button click, it should add an event to mobile calendar. I am receiving an error : Argument of type ‘“2017-04-25”’ is not assignable to parameter of type ‘Date’.

Below is my code:

this.calendar.createEvent(‘Space Race’, ‘The Moon’, ‘Bring sandwiches’,‘2017-04-25’, ‘2017-04-25’)
.then(() => {
console.log(“Success”);
},
()=>{
console.log(“Fail”);
})


#2

The error seems pretty self-explanatory: it wants a Date and you gave it a string.

new Date(2017, 4, 25);

Note: don’t give the Date constructor a string. JavaScript’s string date parsing is notoriously unreliable.


#3

Thanks. Totally missed that.