The date.setMinutes() method is used to set minutes into a Date object which is created using Date() constructor.
// Here a date has been assigned
// while creating Date object
'October 13, 1996 05:35:32'
// New minute of 52 is being set in above Date
// Object with the help of setMinutes() function
// New minute from above Date Object is
// being extracted using getMinutes()
B = dateobj.getMinutes();
// Printing new minute
Parameter: This method accept single parameter as mentioned above and described below:
- minutes_Value: This parameters holds the value of minutes which is used to set in Date() constructor.
Return Value: It returns the new date with updated minute which is set by setMinutes() method.
Note: The DateObj is a valid Date object created using Date() constructor in which we want to set the minute. Value of minute is from 0 to 59.
More codes for the above method are as follows:
Program 1: If in Date() constructor we do not give any minute while creating the Date object, still setMinutes() method set new minute which is given as its parameter.
Example 2: If nothing as parameter is given in Date() constructor, still setMinutes() method set minute but month, year, date etc become current ones. Here 42 is the new minutes, 3 is the current month i.e April, 1 is the current date and 2018 is the current year.
42 3 1 2018
Example 3: If value of minute is 66 as given in the parameter of setMinutes() function, It will set 6 as the minute because minute range is form 0 to 59 and (66%60 = 6).
Here 6 is the new minute and hour becomes 06 from 05 because the minute range is from 0 to 59 i.e, total 60 and we set new minute as 66 which increase hour by one to 06 from 05 and minute becomes 6.
- Google Chrome
- Internet Explorer
- Mozilla Firefox