Reputation: 548
I use this script to get a unique reference for a week in my app :
moment().format(YWW)
witch, today echo 201947 (4 first digit = year of week, 2 last digits = week number). it work great until now.
but I've a problem with the last week of 2019 / first week of 2020 :
The week start at 2019-12-30 but it's the first week of 2020 (with my code, i except 202001) but my code moment("2019-12-30").format('YWW');
return 201901 ! the week number is correct, but not the year (probably because the date of the day is in 2019).
How to update my code to obtain the correct year with my week number ?
thanks
Upvotes: 1
Views: 209
Reputation: 50
Use the GGGG format code for the ISO 4 digit week year:
console.log(moment("2019-12-30").format('GGGGWW'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js" integrity="sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ=" crossorigin="anonymous"></script>
Upvotes: 1