下面是一个例子 日期getUTCDay() 方法
null
- 例子:
javascript
<script> // If nothing is in parameter it takes // the current date while creating Date object var date = new Date(); // Date of the month from above date object // is being extracted using getUTCDay(). var getUTC = date.getUTCDay(); // Printing day of the week document.write(getUTC); </script> |
- 输出:
1
这个 日期getUTCDay() 方法用于根据通用时间从给定的日期对象获取一个月的日期。 语法:
DateObj.getUTCDay();
参数: 此方法不接受任何参数。它只是和一个日期对象一起使用,我们想从中根据世界时间获取月份的日期。 返回值: 它根据世界时间返回给定日期对象的月份日期。月份的日期是1到31之间的整数值。 以上方法的更多代码如下: 项目1: 该月的日期应该在1到31之间,因为没有一个月的日期大于31,这就是它返回NaN的原因,也就是说,不是一个数字,因为该月的日期不存在。
javascript
<script> // Here a date has been assigned according // to universal time while creating a Date object var dateobj = new Date( 'October 33, 1996 05:35:32 GMT-11:00' ); // date of the month from above date object // is being extracted using getUTCDay(). var B = dateobj.getUTCDay(); // Printing day of the week document.write(B); </script> |
输出:
NaN
项目2: 如果未给出月份的日期,则默认情况下getUTCDay()函数根据世界时返回1。这是个例外。
javascript
<script> // Here a date has been assigned according to // universal time while creating Date object var dateobj = new Date( 'October 1996 05:35:32 GMT-11:00' ); // date of the month from above date object is // extracted using getUTCDay(). var B = dateobj.getUTCDay(); // Printing day of the week document.write(B); </script> |
输出:
2
支持的浏览器: 支持的浏览器 JavaScript Date getUTCDay()方法 以下列出了:
- 谷歌Chrome 1及以上版本
- 边缘12及以上
- Firefox 1及以上版本
- Internet Explorer 4及以上版本
- 歌剧4及以上
- Safari 1及以上
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END