#

Javascript: get calendarweek from date
 

//*get current calendarweek in the year
var calendarweek = dt.calendarweek();
 
or
//*get current calendarweek in the year
var calendarweek = new Date().calendarweek();
 
 

 
Ein Bild, das Tisch enthält. Automatisch generierte Beschreibung
 
 
This javascript code extends a date variable by the calendarweek function

Date.prototype.calendarweek = function () {
//------< Date.prototype.calendarweek() >--------
//*extends a date variable by a calendarweek() property
 
var currentdate = this; //current extend date-variable
var january_01 = new Date(currentdate.getFullYear(), 0, 1);
 
//*calendar days already passed
var calendardays = Math.floor((currentdate - january_01) / (24 * 60 * 60 * 1000));
 
//*week by 7days
var calendarweek = Math.ceil((currentdate.getDay() + 1 + calendardays) / 7);
 
//return current calendarweek
return calendarweek;
 
//------</ Date.prototype.calendarweek() >--------
};

 
 
Mobile

.

123movies