Open In App

Moment.js moment.duration().minutes() Method

Last Updated : 23 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The moment().duration().minutes() method is used to get the number of minutes of the duration. This number of minutes is calculated as a subset of an hour, therefore having a value between 0 and 59.

Syntax:

moment().duration().minutes();

Parameters: This method does not accept any parameters.

Return Value: This method returns the minutes (0-59) of the duration.

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.duration().minutes() Method.

Example 1:

Javascript




const moment = require('moment');
  
let durationOne = 
    moment.duration(30, 'minutes');
let durationTwo = 
    moment.duration(105, 'minutes');
  
// This returns 30 as the number of
// minutes is less than a whole hour
console.log(
    "durationOne minutes is:", durationOne.minutes()
)
  
// This returns 45 as the number of minutes
// is greater than 1 hour, and therefore returns the
// value of minutes of the next hour (next 45 minutes)
console.log(
    "durationTwo minutes is:", durationTwo.minutes()
)


Output:

durationOne minutes is: 30
durationTwo minutes is: 45

Example 2: This example will help to understand the difference of this method with asMinutes() for a better understanding.

Javascript




const moment = require('moment');
  
let durationA = 
    moment.duration(2, 'hours');
let durationB = 
    moment.duration({hours: 3, minutes: 52});
  
// The asMinutes() method will return the
// length of the duration in minutes
console.log(
    "Length of durationA in minutes is:",
    durationA.asMinutes()
)
console.log(
    "durationA minutes is:",
    durationA.minutes()
)
  
console.log(
    "Length of durationB in minutes is:",
    durationB.asMinutes()
)
console.log(
    "durationB minutes is:",
    durationB.minutes()
)


Output:

Length of durationA in minutes is: 120
durationA minutes is: 0
Length of durationB in minutes is: 232
durationB minutes is: 52

Reference: https://momentjs.com/docs/#/durations/minutes/



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads