algorithm - JavaScript - get the first day of the week from current date - Stack Overflow Using the...

Please Visit: http://ift.tt/1ajReyV



algorithm - JavaScript - get the first day of the week from current date - Stack Overflow



Using the getDay method of Date objects, you can know the number of day of the week (being 0=Sunday, 1=Monday, etc).

You can then subtract that number of days plus one, for example:

function getMonday(d) {

d = new Date(d);

var day = d.getDay(),

diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday

return new Date(d.setDate(diff));

}

getMonday(new Date()); // Mon Nov 08 2010

http://ift.tt/1gxDur0

http://ift.tt/1oaCRcW



algorithm - JavaScript - get the first day of the week from current date - Stack Overflow







from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1qp2mEF

via LifeLong Community

No comments:

Post a Comment