JavaScript Date getMinutes()
Syntax & Examples
Date.getMinutes() method
The getMinutes() method of the Date object in JavaScript returns the minutes (0 – 59) in the specified date according to local time.
Syntax of Date.getMinutes()
The syntax of Date.getMinutes() method is:
getMinutes()
This getMinutes() method of Date returns the minutes (0 – 59) in the specified date according to local time.
Return Type
Date.getMinutes() returns value of type Number
.
✐ Examples
1 Using getMinutes() to get the minutes of a specific date
In JavaScript, we can use the getMinutes()
method to get the minutes from a Date object.
For example,
- We create a new Date object
date
representing January 15, 2021, at 15:45:00. - We use the
getMinutes()
method to get the minutes fromdate
. - The minutes are stored in the variable
minutes
. - We log
minutes
to the console usingconsole.log()
method.
JavaScript Program
const date = new Date('2021-01-15T15:45:00');
const minutes = date.getMinutes();
console.log(minutes);
Output
45
2 Using getMinutes() with the current date
In JavaScript, we can use the getMinutes()
method to get the current minutes from the current date.
For example,
- We create a new Date object
now
representing the current date and time. - We use the
getMinutes()
method to get the current minutes fromnow
. - The current minutes are stored in the variable
currentMinutes
. - We log
currentMinutes
to the console usingconsole.log()
method.
JavaScript Program
const now = new Date();
const currentMinutes = now.getMinutes();
console.log(currentMinutes);
Output
30
3 Using getMinutes() with a specific date in the past
In JavaScript, we can use the getMinutes()
method to get the minutes from a specific date in the past.
For example,
- We create a new Date object
pastDate
representing July 4, 1776, at 12:15:00. - We use the
getMinutes()
method to get the minutes frompastDate
. - The minutes are stored in the variable
pastMinutes
. - We log
pastMinutes
to the console usingconsole.log()
method.
JavaScript Program
const pastDate = new Date('1776-07-04T12:15:00');
const pastMinutes = pastDate.getMinutes();
console.log(pastMinutes);
Output
15
Summary
In this JavaScript tutorial, we learned about getMinutes() method of Date: the syntax and few working examples with output and detailed explanation for each example.