日期setMinutes()方法以及JavaScript中的示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值