Skip to content

Instantly share code, notes, and snippets.

@lac5
Created June 25, 2019 16:11
Show Gist options
  • Save lac5/04169495c5d48d0f720f3edaf4662a88 to your computer and use it in GitHub Desktop.
Save lac5/04169495c5d48d0f720f3edaf4662a88 to your computer and use it in GitHub Desktop.
let date = new Date();
if (date.getHours() < 5) {
date.setDate(date.getDate() - 1);
}
let thisThu = new Date(date.valueOf() + ((7 - date.getDay()) % 7 - 3) * 86400000);
let firstDay = new Date(thisThu.getFullYear(), 0, 1);
let year = thisThu.getFullYear();
let week = Math.ceil((thisThu.valueOf() - firstDay.valueOf() + 86400000) / 604800000);
let dow = date.getDay() || 7;
console.log(('00' + year).slice(-2) + ('00' + week).slice(-2) + dow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment