Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Calendar Get current date

I've been learning Ruby over the last year and I'm very new to JS so I'll try to explain this as best I can.

I am using Adam Shaw's full calendar plugin. All I want to do is get the current month I am viewing (and use that to limit how far in the future or past a user can navigate, but that's not the problem).

I can get the current date, sort of. But, because of my lack of JS knowledge I'm not sure how to access the date.

Here is the relevant section of the config file,

viewRender: function(view){
  var maxDate = "<%= finish.strftime('%Y/%m/%d') %>";
  var currentDate = $('#calendar').fullCalendar('getDate');
  console.log(currentDate);
  if (view.start > maxDate){
    header.disableButton('prev');

  }
}

When I inspect the console log I see this being output as I click through the months.

console log

So as you can see it is displaying the current date in view. My question is how do I access the _d bit of the Moment variable so I can use it?

My understanding would be that the Moment is class instance and the stuff in the dropdown is like its attributes, would this be a correct interpretation?

like image 592
user3868832 Avatar asked Aug 25 '26 08:08

user3868832


1 Answers

To get the current date of the calendar, do:

var tglCurrent = $('#YourCalendar').fullCalendar('getDate');

This will return the date as a moment object. You can then format it as a string in the usual date format like so:

var tgl=moment(tglCurrent).format('YYYY-MM-DD');

For the actual time, use the format: YYYY-MM-DD LTS

like image 153
ptrnov Avatar answered Aug 26 '26 22:08

ptrnov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!