![]() |
VOOZH | about |
The moment().startOf() method is used to mutate the Moment so that it is set to the start of the given unit of time. The available units of time can be the year, month, quarter, week, day, hour, minute, and second.
Syntax:
moment().startOf( String );
Parameters: This method accepts a single parameter as mentioned above and described below:
Return Value: This method returns the mutated Moment after the value has been set.
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().startOf() Method.
Example 1:
Output:
Current moment is: Mon Jul 18 2022 02:33:56 GMT+0530
startOf current moment's day: Mon Jul 18 2022 00:00:00 GMT+0530
startOf current moment's week: Sun Jul 17 2022 00:00:00 GMT+0530
startOf current moment's month: Fri Jul 01 2022 00:00:00 GMT+0530
startOf current moment's quarter: Fri Jul 01 2022 00:00:00 GMT+0530
startOf current moment's year: Sat Jan 01 2022 00:00:00 GMT+0530
Example 2:
Output:
Current moment is: Mon Jul 18 2022 02:33:56 GMT+0530
startOf current moment's second: Mon Jul 18 2022 02:33:56 GMT+0530
startOf current moment's minute: Mon Jul 18 2022 02:33:00 GMT+0530
startOf current moment's hour: Mon Jul 18 2022 02:00:00 GMT+0530
Reference: https://momentjs.com/docs/#/manipulating/start-of/