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 title like this
titleFormat:
{
month: "'Calendar<br />'MMMM yyyy",
week: "'Calendar<br />Week' W",
day: "'Calendar<br />'dddd dd MMM yyyy"
}
But of course 'W' doesn't exist, is there a way to do that ?
Thanks.
You can turn on week numbers in FullCalendar with this option:
$("#calendar").fullCalendar({
weekNumbers: true
});
Here's a link to the relevant documentation: http://arshaw.com/fullcalendar/docs/display/weekNumbers/
Btw, if I use "W" in title format, then the current week number is inserted (both in month, week and day). Are you using the latest version of FullCalendar? I'm using v. 1.6.1.
- Regin
i have used this code while ago:
<script type="text/javascript" language="JavaScript">
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function getWeek(year,month,day) {
var when = new Date(year,month,day);
var newYear = new Date(year,0,1);
var offset = 7 + 1 - newYear.getDay();
if (offset == 8) offset = 1;
var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;
var weeknum = Math.floor((daynum-offset+7)/7);
if (weeknum == 0) {
year--;
var prevNewYear = new Date(year,0,1);
var prevOffset = 7 + 1 - prevNewYear.getDay();
if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52;
}
return weeknum;
}
var now = new Date();
alert('Week number = ' + getWeek(y2k(now.getYear()),now.getMonth(),now.getDate()));
</script>
its pretty simple, the getWeek() function gets year, month and day, and returns the week number.
Hope that what you wished for.
GoodLuck!
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));
var yearStart = new Date(d.getFullYear(),0,1);
var 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.
Cya
(Sorry for brut text, stackoverflow prevent myself to insert code into the post)
来源:https://stackoverflow.com/questions/17474557/show-week-number-in-fullcalendar