Home » JavaScript

Date setMinutes() method with example in JavaScript

JavaScript Date setMinutes() method: Here, we are going to learn about the setMinutes() method in JavaScript with example.
Submitted by IncludeHelp, on March 13, 2019

JavaScript Date setMinutes() method

setMinutes() method is a Date class method, it is used to set the minutes to the Date object with a valid minutes value (between 00 to 59).

Note: Minutes value larger than the 59 will be truncated from the starting minutes value (00), for example, we are going to set 61 as a minute value, it will be truncated as 1.

Syntax:

    var dt = new Date();
    dt.setMinutes(minute);

Examples:

    Input/Date class object declaration:
    var dt = new Date();

    Function call to set the Minutes:
    dt.setMinutes(45);

    Function call to get the Minutes:
    dt.getMinutes(); 
    
    Output:
    45

JavaScript code to demonstrate an example of Date.setMinutes() method

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date();
	//getting current Minutes
	var Minute = dt.getMinutes();
	//printing
	document.write("Minute: " + Minute + "<br>");
	
	//setting Minute to 45
	dt.setMinutes(45);
	//getting & printing Minutes again
	Minute = dt.getMinutes();
	document.write("Minute: " + Minute + "<br>");	

	//setting invalid Minutes
	//setting Minute to 61
	dt.setMinutes(61);
	//getting & printing Minutes again
	Minute = dt.getMinutes();
	document.write("Minute: " + Minute + "<br>");		
</script>
</body>
</html>

Output

Minute: 2
Minute: 45
Minute: 1

Reference: JavaScript setMinutes() Method






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.