VOOZH about

URL: https://www.geeksforgeeks.org/node-js/moment-js-moment-isoweekyear-method/

⇱ Moment.js moment().isoWeekYear() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Moment.js moment().isoWeekYear() Method

Last Updated : 18 Jul, 2022

The moment().isoWeekYear() method is used to get or set the ISO week year of the Moment object. An ISO week-numbering system considers leap weeks in its system. This allows it to have only 52 or 53 full weeks. This is made possible by considering the number of days to be either 364 or 371 days instead of 365 or 366 days. This makes the method return the same date regardless of its locale.

Syntax:

moment().isoWeekYear( Number );

Parameters: This method accepts a single parameter as mentioned above and described below:

  • Number: It is the ISO Week Year that has to be set for the Moment object. it is an optional parameter.

Return Value: This method returns the current ISO week of the Moment.

Note: This will not work in the normal Node.js program because it requires an external moment.js library to be installed globally or in the project directory.

Moment.js can be installed using the following command:

Installation of moment module:

npm install moment

The below examples will demonstrate the Moment.js moment().isoWeekYear() Method.

Example 1:

Output:

Current Date: Mon Jul 18 2022 01:04:05 GMT+0530
Current isoWeekYear is: 2022
Moment with isoWeekYear of 1 is: Mon Jul 16 0001 01:04:05 GMT+0553
Moment with isoWeekYear of 2 is: Mon Jul 15 0002 01:04:05 GMT+0553
Moment with isoWeekYear of 2010 is: Mon Jul 19 2010 01:04:05 GMT+0530
Moment with isoWeekYear of 2024 is: Mon Jul 15 2024 01:04:05 GMT+0530

Example 2:

Output:

Current Date: Mon Jul 18 2022 01:04:05 GMT+0530
Current isoWeekYear is: 2022
Moment with isoWeekYear of -100 is: Mon Jul 16 -0100 01:04:05 GMT+0553
Moment with isoWeekYear of -2020 is: Mon Jul 14 -2020 01:04:05 GMT+0553

Reference: https://momentjs.com/docs/#/get-set/iso-week-year/

Comment

Explore