get current week number javascript
function getWeekNumber(d) {
// Copy date so don't modify original
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
// Set to nearest Thursday: current date + 4 - current day number
// Make Sunday's day number 7
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7));
// Get first day of year
var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
// Calculate full weeks to nearest Thursday
var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7);
// Return array of year and week number
return [d.getUTCFullYear(), weekNo];
}
var result = getWeekNumber(new Date());
document.write('It\'s currently week ' + result[1] + ' of ' + result[0]);
Also in JavaScript:
- length of list in javascript
- ejs / javascript check if array/object exists and is not empty
- w3schools json
- moving a item fro index to another index, javascript
- javascript click event notifications
- react three fiber
- check equality numbers javascript
- big o theory
- javascript detect touch screen device
- take a screen shot of a image within a div using js
- how to redirect to another page in javascript on submit type
- anonymous function javascript
- useReactiveVar
- angular directive example
- add table header dynamically in jquery
- upload file from url javascript
- ckeditor get content html
- create react native app npx
- js filter array of objects by value
- React hooks update parent state from child
- hidden jquery
- javascript convert to and from binary
- disable input jquery
- how to move an ellipse along the x axis in javascript