Moment.js moment.minute() Method
Last Updated :
12 Mar, 2021
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
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
const moment = require( 'moment' );
var a = moment().minutes(20);
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/
Share your thoughts in the comments
Please Login to comment...