Moment.js根据特定日期(也是过去几年)获取周数

Moment.js根据特定日期(也是过去几年)获取周数

问题描述:

我怎么能从JS的那一刻开始从过去的某个日期开始的星期编号只是从所选日期的格式化对象开始?

How could I get from moment JS the week number from a date in the past only from a moment formatted object from a day selected?

  $(document).ready(function(){
    var weeknumber = moment("12-25-1995", "MM-DD-YYYY").week();
    console.log(weeknumber);
  });

根据momentjs docs:

According momentjs docs:


因为不同的区域设置定义了不同年份的周数,所以
Moment.js添加了一周#周来获取/设置一年中的本地化周。

Because different locales define week of year numbering differently, Moment.js added moment#week to get/set the localized week of the year.

一年中的一周取决于哪一天是每周
的第一天(星期日,星期一等),哪一周是一年
的第一周。

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.

例如,在美国,星期日是
周的第一天。 1月1日这一周是一年中的第一周。

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.

因此,如果您在获得正确的周数时遇到问题使用.isoWeek()

So, if you are having problems getting the right week number use .isoWeek()

$(document).ready(function(){
  var weeknumber = moment("11-26-2016", "MMDDYYYY").isoWeek();
  alert(weeknumber);
});

示例