You can use the getMinutes()
method to get the minutes from a Date
object or from local time in Java. It returns the minute value between 0-59
from the specified date.
dateObject.getMinutes()
The getMinutes()
method does not accept any parameter. It is only called on a Date
object.
It returns an integer between .
If the content of a Date
object is incorrect, the value returned is NaN
.
In the code below, several Date
objects are created and the getMinutes()
method is called on them. The returned values are logged to the console.
// create date objectslet date1 = new Date() // current datelet date2 = new Date('November 4, 2021 12:12:30');let date3 = new Date("2013-05-05, 21:34:20");let date4 = new Date("2025-12-04, 07:02:01");// call the "getMinutes()" methodlet a = date1.getMinutes();let b = date2.getMinutes();let c = date3.getMinutes();let d = date4.getMinutes();// print values returnedconsole.log(a);console.log(b);console.log(c);console.log(d);
In the example below, we will create Date
objects with incorrect parameters. This will cause the getMinutes()
method to return NaN
.
// create datelet date1 = new Date("2012-34-12, 12:12:04"); // Wrong day of the monthlet date2 = new Date("November 50, 2021 03:34:23"); //Wrong day of the monthlet date3 = new Date("April 18, 2012 34:04:25"); // wrong 24hr format// logout returned values of `getMethod()`console.log(date1.getMinutes()) // NaNconsole.log(date2.getMinutes()) // NaNconsole.log(date3.getMinutes()) // NaN