JavaScript日期setMinutes()方法 (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).
setMinutes()方法是Date類的方法,用于將分鐘數設置為具有有效分鐘數值(介于00到59之間)的Date對象。
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.
注意:大于59的分鐘值將從開始的分鐘值(00)中截斷,例如,我們將61設置為分鐘值,它將被截斷為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
JavaScript代碼演示Date.setMinutes()方法的示例
<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
參考: JavaScript setMinutes()方法
翻譯自: https://www.includehelp.com/code-snippets/date-setMinutes-method-with-example-in-javascript.aspx