JavaScript getMinutes() Method
Example
Return the minutes, according to local time:
var d = new Date();
var n = d.getMinutes();
The result of n will be:
Try it yourself »
More "Try it Yourself" examples below.
Definition and Usage
The getMinutes() method returns the minutes (from 0 to 59) of the specified date and time.
Browser Support
Method | |||||
---|---|---|---|---|---|
getMinutes() | Yes | Yes | Yes | Yes | Yes |
Syntax
Date.getMinutes()
Parameters
None |
Technical Details
Return Value: | A Number, from 0 to 59, representing minutes |
---|---|
JavaScript Version: | 1.0 |
More Examples
Example
Return the minutes from a specific date and time:
var d = new Date("July 21, 1983 01:15:00");
var n = d.getMinutes();
The result of n will be:
15
Try it yourself »
Example
Using getHours(), getMinutes(), and getSeconds() to display the time:
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function myFunction() {
var d = new Date();
var x = document.getElementById("demo");
var h =
addZero(d.getHours());
var m =
addZero(d.getMinutes());
var s =
addZero(d.getSeconds());
x.innerHTML = h + ":" + m +
":" + s;
}
Try it yourself »
JavaScript Date Object