Skip to content

Instantly share code, notes, and snippets.

@schafeld
Last active September 15, 2018 11:40
Show Gist options
  • Save schafeld/6abac7a970a8f1a2dbb3519958fc05bc to your computer and use it in GitHub Desktop.
Save schafeld/6abac7a970a8f1a2dbb3519958fc05bc to your computer and use it in GitHub Desktop.
Week of the year (Kalenderwoche)
<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();
}

Week of the year (Kalenderwoche)

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.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment