JavaScript Date setMinutes()
Syntax & Examples
Date.setMinutes() method
The setMinutes() method sets the minutes for a specified date according to local time.
Syntax of Date.setMinutes()
There are 3 variations for the syntax of Date.setMinutes() method. They are:
setMinutes(minutesValue)
Parameters
Parameter | Optional/Required | Description |
---|---|---|
minutesValue | required | An integer between 0 and 59, representing the minutes. |
This method sets the minutes for the specified date.
Returns value of type Number
.
setMinutes(minutesValue, secondsValue)
Parameters
Parameter | Optional/Required | Description |
---|---|---|
minutesValue | required | An integer between 0 and 59, representing the minutes. |
secondsValue | optional | An integer between 0 and 59, representing the seconds. |
This method sets the minutes and seconds for the specified date.
Returns value of type Number
.
setMinutes(minutesValue, secondsValue, msValue)
Parameters
Parameter | Optional/Required | Description |
---|---|---|
minutesValue | required | An integer between 0 and 59, representing the minutes. |
secondsValue | optional | An integer between 0 and 59, representing the seconds. |
msValue | optional | An integer between 0 and 999, representing the milliseconds. |
This method sets the minutes, seconds, and milliseconds for the specified date.
Returns value of type Number
.
✐ Examples
1 Using setMinutes() method with one argument
In JavaScript, we can use the setMinutes() method to set the minutes of a date.
For example,
- Create a new Date object with the current date and time.
- Use the setMinutes() method to set the minutes to 45.
- Log the updated date to the console using console.log().
JavaScript Program
const date = new Date();
date.setMinutes(45);
console.log(date);
Output
Expected output: The date with the minutes set to 45.
2 Using setMinutes() method with two arguments
In JavaScript, we can use the setMinutes() method to set the minutes and seconds of a date.
For example,
- Create a new Date object with the current date and time.
- Use the setMinutes() method to set the minutes to 45 and the seconds to 30.
- Log the updated date to the console using console.log().
JavaScript Program
const date = new Date();
date.setMinutes(45, 30);
console.log(date);
Output
Expected output: The date with the minutes set to 45 and the seconds set to 30.
3 Using setMinutes() method with three arguments
In JavaScript, we can use the setMinutes() method to set the minutes, seconds, and milliseconds of a date.
For example,
- Create a new Date object with the current date and time.
- Use the setMinutes() method to set the minutes to 45, the seconds to 30, and the milliseconds to 500.
- Log the updated date to the console using console.log().
JavaScript Program
const date = new Date();
date.setMinutes(45, 30, 500);
console.log(date);
Output
Expected output: The date with the minutes set to 45, the seconds set to 30, and the milliseconds set to 500.
Summary
In this JavaScript tutorial, we learned about setMinutes() method of Date: the syntax and few working examples with output and detailed explanation for each example.