Now you can listen to this article with the Online Text Reader


JavaScript setMinutes Method





The setMinutes method sets the minute value of the point in time stored in a Date object.

Besides, it can also be used to set the second and the millisecond values, and to increase or decrease the point in time.

The value returned by this method is the quantity of milliseconds passed since January 1st 1970 until the point in time stored in the Date object once it has been modified.


Syntax

The setMinutes method has three overloads:

myDate.setMinutes( minutes )

myDate.setMinutes( minutes, seconds )

myDate.setMinutes( minutes, seconds, milliseconds )

With:
  • minutes being a required parameter that consists of an integer number that, when it is between 0 and 59, changes only the minute value of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining minutes.
  • seconds being an optional parameter that consists of an integer number that, when it is between 0 and 59, changes only the seconds value of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining seconds.
  • milliseconds being an optional parameter that consists of an integer number that, when it is between 0 and 999, changes only the milliseconds value of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining milliseconds.
  • myDate being an object based on the Date object.


Example

The following code uses the setMinutes method to set the minute value of the current point in time to 30:

<script type="text/javascript">

var currentDate = new Date();

var outcome = "Current time is: <br /><br/>" + currentDate.toTimeString();
outcome += "<br/><br/>";

currentDate.setMinutes(30);

outcome += "After changing its minute to 30,  the time is: <br /><br />";
outcome += currentDate.toTimeString();

document.write(outcome);

</script>



Technical Details

The setMinutes method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.





JavaScript Manual >> Date Object >> setMinutes Method





© Copyright 2010-2018 ROM Cartridge



Books to Read and Listen to Online