Skip to content Skip to sidebar Skip to footer

Using Moment.js Trying To Create An Event In Native Ios Calendar

I have used the 'datetime-local' input to get a start date and an end date from the user to put into the native calendar. This is my code to get and format the 'datetime-local':

Solution 1:

You appear to have a typo. Pass e to build the endDate, not s.

var s = $("#startDate").val();
var startDate = moment(s).toDate();
var e = $("#endDate").val();
var endDate = moment(e).toDate(); // <==== this line had used the wrong variable

Or, you could instead just call these inline to avoid confusion:

var startDate = moment($("#startDate").val()).toDate();
var endDate = moment($("#endDate").val()).toDate();

As to why this created an "all day event" - I can't be absolutely certain since I'm not familiar with the particular calendar API you're using. However, it's possible that since you were sending the same start and end time, that it interpreted that as an all day event. I believe fixing the typo will solve the issue.

Post a Comment for "Using Moment.js Trying To Create An Event In Native Ios Calendar"