JavaScript getMinutes(): Get the minutes (0-59)

The JavaScript getMinutes() method is used to get the minutes (0-59) of the time. For example:

HTML with JavaScript Code
<!DOCTYPE html>
   <p id="xyz"></p>

      const d = new Date();
      let minutes = d.getMinutes();
      document.getElementById("xyz").innerHTML = minutes;


In the above example, the following JavaScript statement:

const d = new Date();

creates a new "Date" object with the "new Date()" constructor. This method generates a new date and time object using the current system clock time.

Then using the following JavaScript statement:

let minutes = d.getMinutes();

calls the "Date" object's getMinutes() method to get the current number of minutes (0-59). The "minutes" variable stores this value.

Finally, the following JavaScript statement:

document.getElementById("xyz").innerHTML = minutes;

finds the HTML element with the id attribute "xyz" and sets its innerHTML property to the value stored in the "minutes" variable using the document.getElementById() method. The current number of minutes will be displayed on the web page.

JavaScript getMinutes() syntax

The syntax of the getMinutes() method in JavaScript is:


where x must be an object of the Date() constructor.

The getMinutes() method returns a number from 0 to 59, which will be the minutes of the local time.

Please note: To display the date in the format dd-mm-yyyy, refer to its separate example.

Please note: To display time in the format hh:mm:ss, refer to its separate example.

Please note: To display time in the format hh:mm:ss AM/PM, refer to its separate example.

Advantages of the getMinutes() method in JavaScript

Disadvantages of the getMinutes() method in in JavaScript

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Liked this post? Share it!