This imports MomentJS and uses it to display the current week of the year. Would also work on DevTools console; neat for quickly experimenting with modules, frameworks, whatever...
A Pen by Oliver Schafeld on CodePen.
| <h1>Week of the year: <span id="weekNumber"> <button onClick="setNum()">click to show</button> </span></h1> | |
| // This snippet would print the current week of the year to your DevTools console, just copy into console from here... | |
| var momentJs = document.createElement('script'); | |
| momentJs.src = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"; | |
| document.getElementsByTagName('head')[0].appendChild(momentJs); | |
| // moment().week(); // this will not work here in CodePen (delay needed to load moment.js) | |
| // ...to here. You're welcome. 😇 | |
| var setNum = function () { | |
| var elem = document.getElementById("weekNumber"); | |
| elem.innerHTML = moment().week(); | |
| } |
This imports MomentJS and uses it to display the current week of the year. Would also work on DevTools console; neat for quickly experimenting with modules, frameworks, whatever...
A Pen by Oliver Schafeld on CodePen.