Javascript Date getWeek()
Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7); }
'use strict';//from w w w . j av a 2 s.co m Date.prototype.getWeek = function () { var firstOfJanuary = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - firstOfJanuary) / 86400000) + firstOfJanuary.getDay() + 1) / 7); };
Date.prototype.getWeek = function() { var dt = new Date(this.getFullYear(),0,1); return Math.ceil((((this - dt) / 86400000) + dt.getDay()+1)/7); }; var AccountController = { index: function (req,res) { return res.view(); }//w w w. java2 s . c o m }; module.exports = AccountController;
// adds getWeek of the year to Date Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7); };
Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7); }
//this is some hardcore shit, right^ Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(),0,1); var today = new Date(this.getFullYear(),this.getMonth(),this.getDate()); var dayOfYear = ((today - onejan + 86400000)/86400000); return Math.ceil(dayOfYear/7) }; var today = new Date(); var currentWeekNumber = today.getWeek(); console.log(currentWeekNumber);//from w w w .ja v a 2 s .c om alert("The current week number is:\n"+currentWeekNumber); window.history.back();
Date.prototype.getWeek = function(){ var d = new Date(+this); d.setHours(0,0,0);//from ww w .j av a 2s.c om d.setDate(d.getDate()+4-(d.getDay()||7)); return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7); }; Date.prototype.setInterval = function(type, nb) { if(type === 'month') {this.setMonth(this.getMonth()+nb);} if(type === 'year') {this.setFullYear(this.getFullYear()+nb);} if(type === 'week') {this.setDate(this.getDate()+(7*nb));} }
Date.prototype.getWeek = function() { var tmpDate = new Date(); tmpDate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate()); var D = tmpDate.getDay(); if(D == 0) D = 7; tmpDate.setDate(tmpDate.getDate() + (4 - D)); var YN = tmpDate.getFullYear(); var ZBDoCY = Math.floor((tmpDate.getTime() - new Date(YN, 0, 1, -6)) / 86400000); var WN = 1 + Math.floor(ZBDoCY / 7); return WN;//w w w .ja v a 2s .c o m };
Date.prototype.getWeek = function() { var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate())); var dayNum = d.getUTCDay() || 7; d.setUTCDate(d.getUTCDate() + 4 - dayNum); var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); return Math.ceil((((d - yearStart) / 86400000) + 1)/7); }
function pad (str, max) { str = str.toString();/* w ww. j av a 2 s . c o m*/ return str.length < max ? pad("0" + str, max) : str; } Date.prototype.getWeek = function() { var date = new Date(this.getTime()); date.setHours(0, 0, 0, 0); // Thursday in current week decides the year. date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); // January 4 is always in week 1. var week1 = new Date(date.getFullYear(), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7); }
Date.prototype.getWeek = function() { //https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate())); var dayNum = d.getUTCDay() || 7; d.setUTCDate(d.getUTCDate() + 4 - dayNum); var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); return Math.ceil((((d - yearStart) / 86400000) + 1)/7); }
// Date.prototype.getWeek = function() { // var onejan = new Date(this.getFullYear(),0,1) // return Math.ceil( ( ((this - onejan) / 86400000) + onejan.getDay() + 1 ) / 7 ) // }//www . j av a 2 s.com Date.prototype.getWeek = function(){ var d = new Date( Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()) ) var n = d.getUTCDay() || 7 d.setUTCDate( d.getUTCDate() + 4 - n ) var yearStart = new Date( Date.UTC(d.getUTCFullYear(), 0, 1) ) return Math.ceil( ( ((d - yearStart) / 86400000) + 1 ) / 7 ) } function formatDate(d, name){ var months = ["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"] name += " (" + d.getDate() name += " " + months[d.getMonth()] name += ", week " + d.getWeek() + ")" return name }
Date.prototype.getWeek = function() { var determinedate = new Date(); determinedate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate()); var D = determinedate.getDay(); if(D == 0) D = 7; determinedate.setDate(determinedate.getDate() + (4 - D)); var YN = determinedate.getFullYear(); var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000); var WN = 1 + Math.floor(ZBDoCY / 7); return WN;//from w w w . j a v a2 s . c o m }