I use node.js with moment 2.9.0
var moment = require("moment");
var d = moment.utc([2014, 11, 27]);
var iso = d.toISOString();
var week = d.week();
shows iso = "2014-12-27T00:00:00.000Z" and week is 52.
But if var d = moment.utc([2014, 11, 28]);
iso is 2014-12-28T00:00:00.000Z
week is 1. Why?
Thank you.
The answer can be found in the docs:
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.
For example, in the United States, Sunday is the first day of the week. The week with January 1st in it is the first week of the year.
So, week #1 of 2015 (by this function) is:
It's also worth mentioning that moment also has the isoWeek
function, which conforms to the ISO 8601 week numbering system.