JavaScript Date setMinutes() method

The setMinutes method in JavaScript is utilized to adjust the minutes of a given date according to local time.

Syntax

The method setMinutes can be expressed using the syntax as follows:

Example

dateObj.setMinutes( minValue[, secValue[, msValue]]])

Parameter

minValue - This denotes an integer ranging from 0 to 59, indicating the minutes. Should the specified minute value exceed 59, the setMinutes function will automatically adjust the hour value as needed.

secValue? This parameter is not mandatory. It denotes an integer ranging from 0 to 59, indicating the seconds. In cases where the supplied second value exceeds 59, the setMinutes function will adjust the minute value accordingly.

msValue? This parameter is optional. It denotes an integer ranging from 0 to 999, which indicates the milliseconds. In cases where the millisecond value exceeds 999, the setMinutes function will automatically adjust the seconds value accordingly.

JavaScript Date setMinutes method example

In this section, we will explore the setMinutes method by examining several examples.

Example 1

Let’s consider an example that demonstrates how to output both the current and the modified minute value.

Example

<script>

var minutes=new Date();	

document.writeln("Current Minute : "+minutes.getMinutes()+"<br>");

minutes.setMinutes(32);

document.writeln("Updated Minute : "+minutes.getMinutes());

</script>

Output:

Output

Current Minute : 57

Updated Minute : 32

Example 2

Let’s examine an example that demonstrates how to modify the minute component of a specified time.

Example

<script>

var minutes=new Date("August 15, 1947 20:22:10");	

minutes.setMinutes(32);

document.writeln("Updated Minute : "+minutes.getMinutes());

</script>

Output:

Output

Updated Minute : 32

Example 3

In this illustration, we will define the seconds value (which exceeds 59) in conjunction with the minutes.

Example

<script>

var minutes=new Date("August 15, 1947 20:22:10");	

minutes.setMinutes(22,62);

document.writeln("Updated Minute : "+minutes.getMinutes());

</script>

Output:

Output

Updated Minute : 23

Input Required

This code uses input(). Please provide values below: