Javascript Date weekOfYear()

Description

Javascript Date weekOfYear()


Date.prototype.weekOfYear = function () {
    var year = this.getFullYear();
    var d = new Date(this);
    d.setHours(0, 0, 0, 0);/*  w  w  w .j ava2s. c o  m*/

    var yearStart = new Date(year, 0, 1);

    d.setDate(d.getDate() + yearStart.getDay());
    var deltaDay = (d.getTime() - yearStart.getTime()) / 86400000 + 1;
    var weekNo = Math.ceil(deltaDay / 7);
    return [year, weekNo];
};



PreviousNext

Related