moment().weeksInYear()方法用于返回Moment对象当前年份的周数。此方法是特定于区域设置的,因此该数字可能会根据 Moment 的当前区域设置而有所不同。
用法:
moment().weeksInYear();
参数:该方法不接受任何参数。
返回值:此方法返回 Moment 对象当前年份的周数。
注意:这在普通的 Node.js 程序中不起作用,因为它需要全局安装或在项目目录中安装外部moment.js 库。
Moment.js 可以使用以下命令安装:
moment模块的安装:
npm install moment
以下示例将演示 Moment.js moment().weeksInYear() 方法。
示例 1:
Javascript
const moment = require('moment');
console.log("Current Date:", moment().toString())
console.log("Current year is:", moment().year())
let year2050 = moment().year(2050);
console.log(
"Weeks in Year 2050 is:",
year2050.weeksInYear()
)
let year1950 = moment().year(1950);
console.log(
"Weeks in Year 1950 is:",
year1950.weeksInYear()
)
输出:
Current Date: Mon Jul 11 2022 02:14:41 GMT+0530 Current year is: 2022 Weeks in Year 2050 is: 53 Weeks in Year 1950 is: 52
示例 2:
Javascript
const moment = require('moment');
console.log("Current Date:", moment().toString())
console.log("Current year is:", moment().year())
for (let i = 2000; i < 2030; i++) {
console.log(
`Weeks in Year ${i} is: ${moment().year(i).weeksInYear()}`
)
}
输出:
Weeks in Year 2000 is: 53 Weeks in Year 2001 is: 52 Weeks in Year 2002 is: 52 Weeks in Year 2003 is: 52 Weeks in Year 2004 is: 52 Weeks in Year 2005 is: 53 Weeks in Year 2006 is: 52 Weeks in Year 2007 is: 52 Weeks in Year 2008 is: 52 Weeks in Year 2009 is: 52 Weeks in Year 2010 is: 52 Weeks in Year 2011 is: 53 Weeks in Year 2012 is: 52 Weeks in Year 2013 is: 52 Weeks in Year 2014 is: 52 Weeks in Year 2015 is: 52 Weeks in Year 2016 is: 53 Weeks in Year 2017 is: 52 Weeks in Year 2018 is: 52 Weeks in Year 2019 is: 52 Weeks in Year 2020 is: 52 Weeks in Year 2021 is: 52 Weeks in Year 2022 is: 53 Weeks in Year 2023 is: 52 Weeks in Year 2024 is: 52 Weeks in Year 2025 is: 52 Weeks in Year 2026 is: 52 Weeks in Year 2027 is: 52 Weeks in Year 2028 is: 53 Weeks in Year 2029 is: 52
参考:https://momentjs.com/docs/#/get-set/weeks-in-year/
相关用法
- Moment.js moment().week()用法及代码示例
- Moment.js moment().weekYear()用法及代码示例
- Moment.js moment().calender()用法及代码示例
- Moment.js moment().daysInMonth()用法及代码示例
- Moment.js moment().diff()用法及代码示例
- Moment.js moment().format()用法及代码示例
- Moment.js moment().from()用法及代码示例
- Moment.js moment().fromNow()用法及代码示例
- Moment.js moment().to()用法及代码示例
- Moment.js moment().toNow()用法及代码示例
- Moment.js moment().unix()用法及代码示例
- Moment.js moment().valueOf()用法及代码示例
- Moment.js moment().millisecond()用法及代码示例
- Moment.js moment().set()用法及代码示例
- Moment.js moment().toString()用法及代码示例
- Moment.js moment().local()用法及代码示例
- Moment.js moment().min()用法及代码示例
- Moment.js moment().get()用法及代码示例
- Moment.js moment().startOf()用法及代码示例
- Moment.js moment().isoWeeksInYear()用法及代码示例
- Moment.js moment().toArray()用法及代码示例
- Moment.js moment().utcOffset()用法及代码示例
- Moment.js moment().zone()用法及代码示例
- Moment.js moment().add()用法及代码示例
- Moment.js moment().inspect()用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 Moment.js moment().weeksInYear() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。