0

I am creating a todo app in nativescript using this plugin by Eddy https://github.com/EddyVerbruggen/nativescript-calendar.

The issue i have is with the date option, precisely startDate and endDate.

i am trying to set the day of the event e.g November 31, 2016 and the time it starts e.g 8:00am. In the doc, it is done like this:

//an Event for now + 1 hour, lasting 1 hour.
startDate: new Date(new Date().getTime() + (60*60*1000)),
endDate: new Date(new Date().getTime() + (2*60*60*1000))

i have tried diffrent ways to achieve what i need but none works.

My latest trial is shown below and it gives the error getTime() is not a function:

startDate: new Date(Date(viewModel.scheduleDay).getTime() + (60*60*1000)),
startDate: new Date(Date(viewModel.scheduleDay).getTime() + (60*60*1000)),

i tired just to get for same day, it worked using this:

startDate: new Date(new Date().setTime(viewModel.scheduleTime)),
endDate: new Date(new Date().setTime(viewModel.scheduleTime))

What i need to do is set the date and time for the event to start.

Thanks.

Dammy joel
  • 544
  • 3
  • 8
  • *"i have tried diffrent ways to achieve what i need but none works."* The code just above that absolutely sets `startDate` to "now plus one hour" and `endDate` to "now plus two hours". Please add a **runnable** [mcve] to the question using Stack Snippets (the `<>` toolbar button) so we can help you. – T.J. Crowder Nov 25 '16 at 18:42
  • I am not use if i fully get what you need me to do... I got that code from the documentation for the plugin i am using. It's just an example of how it was used. here is the link to the page with the full info. https://github.com/EddyVerbruggen/nativescript-calendar you will find it under createEvent section. Thanks – Dammy joel Nov 25 '16 at 18:49
  • Use "edit" to edit your question, then click the `<>` toolbar button to create a Stack Snippet. This opens a jsFiddle-like editor. Add any scripts you need to add via the External Libs button, add your code and markup, and make sure it runs and demonstrates the problem you're having. – T.J. Crowder Nov 25 '16 at 18:54
  • Okay, i get it now. And i tried to do as you said, but it wont really be any useful. I tested my code well i know beyond measure that the problem will be solved if i know how to set the future date and time. Also i am building a mobile app not a web app, so using that js fiddle like interface will not run the app. The framework i am using allows me to use js, css and xml to build cross platform mobile apps. https://www.nativescript.org/ Thanks again. – Dammy joel Nov 25 '16 at 19:19
  • Use moment.js and call it a day :p – Brad Martin Nov 25 '16 at 19:49
  • 1
    Will check out moment.js thanks @Brad Martin – Dammy joel Nov 25 '16 at 20:23
  • You really don't need a library to create a date for a specific date and time, nor to increment it by some amount. See [*Add +1 to current date*](http://stackoverflow.com/questions/9989382/add-1-to-current-date/9989458#9989458). The same method can be used to increment or decrement any part of a date. – RobG Nov 26 '16 at 07:41

0 Answers0