下面是Date setUTCMinutes()方法的示例。
- 例:
<script> // Here a date has been assigned according to // universal time while creating Date object var dateobj = new Date('October 13, 1996 05:35:32 GMT-3:00'); // New minute of 52 is being set in above Date // Object with the help of setUTCMinutes() method dateobj.setUTCMinutes(52); // New minute from above Date Object is // being extracted using getUTCMinutes() var B = dateobj.getUTCMinutes(); // Printing new minute document.write(B); </script>
- 输出:
52
date.setUTCMinutes()方法用于根据通用时间将分钟设置为使用Date()构造函数创建的日期对象。
用法:
DateObj.setUTCMinutes(Minutes_Value);
参数:该方法接受上述和以下描述的单个参数:
- minutes_Value:此参数保存我们要在使用Date()构造函数创建的日期中设置的分钟值。
返回值:它返回由setUTCMinutes()方法设置的新的即更新的分钟。
注意:DateObj是使用Date()构造函数创建的有效Date对象,我们要在其中设置分钟。分钟的值是从0到59。
上述方法的更多代码如下:
范例1:如果在Date()构造函数中创建日期对象时没有给出任何分钟,则setUTCMinutes()方法仍然可以根据创建的Date对象中的通用时间设置新分钟。
<script>
// Here minute has not been assigned according to
// universal time while creating Date object
var dateobj = new Date('October 13, 1996 GMT-3:00');
// New minute of 51 is being set in above Date
// Object with the help of setUTCMinutes() method
dateobj.setUTCMinutes(51);
// New minute from above Date Object is
// being extracted using getUTCMinutes()
var B = dateobj.getUTCMinutes();
// Printing new minute
document.write(B);
</script>
输出:
51
范例2:如果在Date()构造函数中未提供任何参数作为参数,则仍然可以设置setUTCMinutes()方法为分钟,但是月份,年份,日期等仍为当前值。
这里42是新分钟,3是当前月,即4月,1是当前日期,2018是当前年。
<script>
// Here nothing has been assigned according to
// universal time while creating Date object
var dateobj = new Date();
// New minute of 42 is being set in above Date
// Object with the help of setUTCMinutes() method
dateobj.setUTCMinutes(42);
// Minutes from above Date Object is
// being extracted using getUTCMinutes()
var B = dateobj.getUTCMinutes();
// Month from above Date Object is
// being extracted using getUTCMonth()
var C = dateobj.getUTCMonth();
// Date from above Date Object is
// being extracted using getUTCDate()
var D = dateobj.getUTCDate();
// Year from above Date Object is
// being extracted using getUTCFullYear()
var E = dateobj.getUTCFullYear();
// Printing new minutes
document.write(B + "<br />");
// Printing current month
document.write(C + "<br />");
// Printing current date
document.write(D + "<br />");
// Printing current year
document.write(E);
</script>
输出:
42 3 1 2018
范例3:如果将分钟值设为66作为setUTCMinutes()方法的参数,则它将6设置为分钟,因为分钟范围是从0到59,因此,这里减去60,因为0到59是60。
<script>
// Here date has been assigned according to
// universal time while creating Date object
var dateobj =
new Date('October 13, 1996 05:35:32 GMT-3:00');
// New minute of 66 is being set in above Date
// Object with the help of setUTCMinutes() method
dateobj.setUTCMinutes(66);
// Minute from above Date Object is
// being extracted using getUTCMinutes()
var B = dateobj.getUTCMinutes();
// Hour from above Date Object is
// being extracted using getUTCHours()
var C = dateobj.getUTCHours();
// Printing new minute
document.write(B + "<br />");
// Printing hour
document.write(C);
</script>
输出:
6 6
支持的浏览器:下面列出了JavaScript Date setUTCMinutes()方法支持的浏览器:
- 谷歌浏览器
- IE浏览器
- 火狐浏览器
- Opera
- Safari
相关用法
- JavaScript Date toLocaleTimeString()用法及代码示例
- JavaScript Date UTC()用法及代码示例
- JavaScript Date getHours()用法及代码示例
- Javascript date.getMinutes()用法及代码示例
- Javascript date.getMonth()用法及代码示例
- Javascript date.getSeconds()用法及代码示例
- Javascript date.getDay()用法及代码示例
- JavaScript Date getMilliseconds()用法及代码示例
- JavaScript Date getFullYear()用法及代码示例
- JavaScript Date getDate()用法及代码示例
- JavaScript Date getUTCDate()用法及代码示例
- JavaScript Date getUTCDay()用法及代码示例
- JavaScript Date getUTCFullYear()用法及代码示例
- JavaScript Date getUTCHours()用法及代码示例
- JavaScript Date getUTCMilliseconds()用法及代码示例
- JavaScript Date getUTCSeconds()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 JavaScript Date setUTCMinutes() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。