Moment.js moment.minute() Method
The moment().minute() Method is used to get the minutes from the current time or to set the minutes.
Syntax:
moment().minute();
or
moment().minutes();
Parameters: This method accepts a single parameter number that you want to set minutes then you will require an additional parameter:
Number: It ranges from 0 to 59 and used to set minutes in a variable.
Return Value: This function returns the current time in minutes.
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:
Installing module:
npm install moment
Example 1: Getting the current time in minutes.
index.js
// Importing moment module const moment = require( 'moment' ); var a = moment().minutes(); console.log( "minute is: " ,a); |
Run index.js file using below command:
node index.js
Output:
minute is: 24
Example 2: Setting minutes of time.
index.js
// Importing moment module const moment = require( 'moment' ); var a = moment().minutes(20); // Printing the updated minutes console.log(a); |
Run index.js file using below command:
node index.js
Output:
Moment<2021-02-10T22:20:29+05:30>
Reference: https://momentjs.com/docs/#/get-set/minute/