下面是一个例子 日期设置utcMinutes() 方法
null
- 例子:
javascript
<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
这个 日期setUTCMinutes() 方法用于根据世界时间将分钟设置为日期对象,该对象是使用date()构造函数创建的。
语法:
DateObj.setUTCMinutes(Minutes_Value);
参数: 此方法接受一个参数,如上所述,如下所述:
- 分钟值: 此参数保存要在使用date()构造函数创建的日期中设置的分钟值。
返回值: 它返回由setUTCMinutes()方法设置的新的即更新的分钟数。
注: 这个 DateObj 是使用Date()构造函数创建的有效日期对象,我们希望在其中设置分钟。分钟的值从0到59。
以上方法的更多代码如下: 例1: 如果在Date()构造函数中,我们在创建Date对象时没有给出任何分钟,那么仍然setUTCMinutes()方法将能够根据创建的Date对象中的通用时间设置新的分钟。
javascript
<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()构造函数中没有给出任何参数,still setUTCMinutes()方法将能够设置分钟,但月、年、日期等仍为当前值。 这里42是新的会议记录,3是当前月份,即4月,1是当前日期,2018年是当前年份。
javascript
<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: 如果将minute的值设为66作为setUTCMinutes()方法的参数,它会将6设为minute,因为minute的范围是0到59,因此 ,这里减去60,因为0到59是60。
javascript
<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()方法 以下列出了:
- 谷歌Chrome 1及以上版本
- 边缘12及以上
- Firefox 1及以上版本
- Internet Explorer 4及以上版本
- 歌剧4及以上
- Safari 1及以上
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END