我怎样才能从时刻 JS 获取过去日期的周数,只能从选定日期的时刻格式化对象中获取?
最佳答案
$(document).ready(function(){
var weeknumber = moment("12-25-1995", "MM-DD-YYYY").week();
console.log(weeknumber);
});
根据 momentjs 文档:
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.
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()
$(document).ready(function(){
var weeknumber = moment("11-26-2016", "MMDDYYYY").isoWeek();
alert(weeknumber);
});
关于javascript - Moment.js 根据特定日期(也是过去几年)获取周数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25953551/