![]() |
VOOZH | about |
The moment().day() method in Moment.js returns or sets the day of the week for a moment object, where Sunday is represented as 0 and Saturday as 6. It helps manipulate and format weekday data easily in JavaScript.
moment().weekday( Number );Parameters: This method accepts a single parameter as mentioned above and described below:
Return Value: This method returns the current day of the 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.
Installation of moment module:
npm install momentExample 1: The below examples will demonstrate the Moment.js moment().day() Method.
Output:
Current Date: Mon Jul 18 2022 01:21:54 GMT+0530
Current day is: 1
This week's Wednesday is: Wed Jul 20 2022 01:21:54 GMT+0530
This week's Saturday is: Sat Jul 23 2022 01:21:54 GMT+0530
This week's Monday is: Mon Jul 18 2022 01:21:54 GMT+0530
Example 2: The below examples will demonstrate the Moment.js moment().day() Method.
Output:
Current Date: Mon Jul 18 2022 01:21:54 GMT+0530
Current day is: 1
Next week's Wednesday is: Wed Jul 27 2022 01:21:54 GMT+0530
Previous week's Wednesday is: Wed Jul 13 2022 01:21:54 GMT+0530
Next week's Sunday is: Sun Jul 31 2022 01:21:54 GMT+0530