Show week number in FullCalendar

后端 未结 3 1607
星月不相逢
星月不相逢 2021-01-25 04:09

I\'m looking for a way to show the week number on the agendaWeek view. I\'ve tried this method but without result.

Actually, I need to put the number in the calendar tit

3条回答
  •  无人共我
    2021-01-25 04:55

    I found a way to do this and it works for me :

    Place this in the settings :

    viewDisplay: function(view) {
          if (view.name == 'agendaWeek')
          {
              $("table.fc-header span.fc-header-title h2").append("
    Week " + getWeekNumber(view.start)); } }, // others settings...

    Place this in the same file, before the fullcalendar settings

    function getWeekNumber(d) {
      d = new Date(d);
      d.setHours(0, 0, 0);
    
      d.setDate(d.getDate() + 4 - (d.getDay() || 7));
    
      const yearStart = new Date(d.getFullYear(), 0, 1);
    
      const weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
    
      return weekNo;
    }
    

    And that's that. Thank you for your previous answer, I'm going to try to update my fullcalendar version.

提交回复
热议问题