In javaScript, the moment.js
package or module provides us the ability to manipulate dates and times easily. With its minutes()
, also referred to as the minute
method, we can get or set the minutes of a date or time.
// get minutesmoment(datetime).minutes()// set minutesmoment(datetime).minutes(Number)
datetime
: This is the date or time we want to get or set its minutes.Number
: This is the number of minutes we want to set our date or time. It can only be from 0
to 59
. If it is exceeded then it will bubble up to the hour.This method returns an integer value from 0
to 59
.
Let's look at the code below:
// require the moment moduleconst moment = require("moment")// create some dates and timeconst date1 = moment(); // current date and timeconst date2 = moment('2020.01.01', 'YYYY.MM.DD')const date3 = moment([2010, 1, 14, 15, 25, 50, 125])const date4 = moment(new Date) // current date and timeconst time1 = moment(1318781876406)const time2 = moment({hour: 20, minute: 20, second: 34})// get the minutes of the time and datesconsole.log(date1.minutes())console.log(date2.minutes())console.log(date3.minutes())console.log(date4.minutes())console.log(time1.minutes())console.log(time2.minutes())
In the code above:
moment
package.moment
package.minutes()
method to get the minutes of the dates and times created. Let's look at another example:
// require the moment moduleconst moment = require("moment")// create some dates and timeconst date1 = moment(); // current date and time// get the minutesconsole.log(date1.minutes())// now set the minutesdate1.minutes(59)// get the minutes againconsole.log(date1.minutes())
In the code above:
moment
module.minutes()
method to get the minutes of the date we created and print them to the console.59
.