JavaScript setMinutes

The JavaScript setMinutes function is used to set the Minutes, Seconds, and Milliseconds of a given date as per local time.

The syntax of the setMinutes function is:

 Date.setMinutes(Minutes, Seconds, Milliseconds)

Parameter: The syntax of the JavaScript setMinutes() method accepts three parameters.

  • Minutes: It accepts minutes value range between 0 and 59 to pass it to the original date and time.
  • Seconds (optional): It accepts seconds values ranging between 0 and 59.
  • Milliseconds (optional):  It accepts milliseconds values, ranging between 0 and 999.

If you pass a minute value above 59 or above (for Example, 100), it considers 60 minutes as 1 hour and adds 1 hour to the existing date, setting the remaining 40 as a minute value.

Return Value: The setMinutes() method returns a new and updated date with the given minutes, seconds, and milliseconds. If the parameter value is NaN or undefined, the date becomes invalid, and the setMinutes() result is NaN.

JavaScript setMinutes example

In the following example, we use the setMinutes() method to set the minute value to 30 for the current date and time. If you observe the output, the time 9:58 becomes 9:30.

let dt = new Date();
console.log(dt);
dt.setMinutes(30);

console.log(dt);
console.log(dt.getMinutes());
Mon Jun 15 2026 09:58:40 GMT+0530 (India Standard Time) 
Mon Jun 15 2026 09:30:40 GMT+0530 (India Standard Time) 
30

Example 2: In this example, we use the JavaScript setMinutes function to set a minute value to 45 for a custom date and time.

let dt = new Date("January 1, 2023 10:11:22");
dt.setMinutes(45);
console.log(dt);
Sun Jan 01 2023 10:45:22 GMT+0530 (India Standard Time)

Example 3: If we use the setMinutes() method on a custom date without a time value, the Date() object considers 0 as the default minutes value. The setMinutes() method sets the minute value by the given number of minutes.

let dt = new Date("January 1, 2022");
console.log(dt);
dt.setMinutes(25);
console.log(dt);
Sat Jan 01 2022 00:00:00 GMT+0530 (India Standard Time) 
Sat Jan 01 2022 00:25:00 GMT+0530 (India Standard Time)

Example 4: As we mentioned earlier, in this JavaScript setMinutes function, the seconds and Milliseconds arguments are optional. Let me use all three parameters.

NOTE: In JavaScript, to use seconds, minutes is mandate, and to use milliseconds, we must use the seconds and milliseconds parameters.

let dt = new Date("January 1, 2023 10:11:22.111");
console.log(dt);
dt.setMinutes(45, 30, 555);
console.log(dt.toString());
console.log(dt.getMinutes());
console.log(dt.getSeconds());
console.log(dt.getMilliseconds());
Sun Jan 01 2023 10:11:22 GMT+0530 (India Standard Time) 
Sun Jan 01 2023 10:45:30 GMT+0530 (India Standard Time) 
45 
30 
555

TIP: Please use the getMinutes(), getSeconds(), and getMilliseconds() methods to extract the minutes, seconds, and milliseconds from the date object.

Example 5: As we mentioned earlier, if we pass a minute value greater than 59, it updates the hours value based on the number of minutes.

In the example below, we used the setMinutes() method with 150 minutes. Here, 150 minutes means 2 Hours and 30 Minutes. So, the setMinutes() method sets the current date and time ahead by 2 hours and 30 minutes.

let dt = new Date();
console.log(dt);
dt.setMinutes(150);
console.log(dt);
Mon Jun 15 2026 10:12:08 GMT+0530 (India Standard Time) 
Mon Jun 15 2026 12:30:08 GMT+0530 (India Standard Time)

Example 6: Using JavaScript setMinutes() with negative minutes

If we use the setMinutes() function with a negative minute value, it sets the time to the previous hour’s last minute. Here, the time is 10:15:15, and the previous hour’s last minute is 09:59. So, the result is 09:59:15.

let dt = new Date();
console.log(dt);
dt.setMinutes(-1);
console.log(dt);
Mon Jun 15 2026 10:15:15 GMT+0530 (India Standard Time) 
Mon Jun 15 2026 09:59:15 GMT+0530 (India Standard Time)

How to add 30 minutes to a JavaScript Date Object?

We can use the combination of setMinutes() and getMinutes() methods to add 30 minutes to the current date or a custom date and time.

let dt = new Date();
console.log(dt);
dt.setMinutes(dt.getMinutes() + 30);
console.log(dt);
Mon Jun 15 2026 10:18:26 GMT+0530 (India Standard Time) 
Mon Jun 15 2026 10:48:26 GMT+0530 (India Standard Time)

An alternative approach, adding 30 minutes to a date, is using the getTime() function.

let dt = new Date();
console.log(dt);
let t = new Date(dt.getTime() + 30 * 60 * 1000);
console.log(t);
Mon Jun 15 2026 10:19:29 GMT+0530 (India Standard Time) 
Mon Jun 15 2026 10:49:29 GMT+0530 (India Standard Time)