user3868832
user3868832

Reputation: 620

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?

Upvotes: 3

Views: 25467

Answers (3)

Piter Novian
Piter Novian

Reputation: 41

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

Upvotes: 4

brandelizer
brandelizer

Reputation: 352

var moment = $('#YourCalendar').fullCalendar('getDate');
var calDate = moment.format('DD.MM.YYYY HH:mm'); //Here you can format your Date

Upvotes: 1

Patel
Patel

Reputation: 1478

FullCalendar's getDate returns a moment object, so you need moment's toDate() method to get date out of it.

So, in you code try:

console.log(currentDate.toDate());

and that should return a date object.

Upvotes: 3

Related Questions