How to find dynamically next month and year using js moment in jQuery

I have two calendars on my page that are implemented using the full jQuery calendar plugin.

I need to download calendars, such as the remaining calendars and the calendar for the upcoming month. As with November, the correct calendar should be December. What I could do by indicating the dates.

But I have two navigation arrows to navigate the calendar to the left and right of these calendars. How can I get dynamics in the next month and year and vice versa, i.e. The previous month and previous year are provided month and year.

I found a way to get the current current month and year using moment.js, which will handle a leap year and all ...

Below is the code to get the current date. I need to know how I can get a preview of the month and year, and the next month and year for navigation clicks.

the code:

var eNow = new Date(); var eMoment = moment(eNow); var leftEMonth = eMoment.format('MM')-1; var leftEYear = eMoment.format('YYYY'); 
+5
source share
1 answer

Months:

 moment().add(1, 'months'); 

Years:

 moment().add(1, 'years'); 

So, for example, the next month’s button will look like this:

 $('#nextMonthBtn').click(function () { eMoment.add(1, 'months'); }); 

Assuming eMoment, of course, is included in the scope.

+14
source

Source: https://habr.com/ru/post/1206411/


All Articles