• JavaScript Video Tutorials

JavaScript Date getMinutes() Method



The Date.getMinutes() method in JavaScript is used to retrieve the minutes component of a date object, representing the minutes of the hour as a number between 0 and 59. It extracts the minutes portion of a date object, based on the system's local time zone.

If no date is provided as an argument, the getMinutes() method returns the minutes component of the Date object it is called on, based on local time. If the Date object is invalid, this method returns NaN as result.

Syntax

Following is the syntax of JavaScript Date getMinutes() method −

getMinutes();

This method does not accept any parameters.

Return Value

This method returns an integer value representing the minutes component of the given Date object, ranging from 0 to 59.

Example 1

In the following example, we are demonstrating the basic usage of JavaScript Date getMinutes() method −

<html>
<body>
<script>
   const currentDate = new Date();
   const minutes = currentDate.getMinutes();

   document.write("Current Minutes:", minutes);
</script>
</body>
</html>

Output

The above program returns the minutes of a date according to the local time.

Example 2

Here, we are fetching the minute component from the provided date using the getMinutes() method.

<html>
<body>
<script>
   const specificDate = new Date('2023-12-25 12:45:30');
   const minutes = specificDate.getMinutes();

   document.write("Minutes of provided Date:", minutes);
</script>
</body>
</html>

Output

The above program returns integer 45 as minutes value.

Advertisements