date.getUTCMinutes()是JavaScript中的內置函數,用於根據通用時間從給定的Date對象獲取分鍾。
用法:
DateObj.getUTCMinutes();
在以上語法中,DateObj是使用Date()構造函數創建的有效Date對象,我們想從中獲取分鍾數。
參數:此函數不帶任何參數。它僅與我們要從中獲取分鍾數的Date對象一起使用。
返回值:它根據世界通用時間返回給定日期的分鍾數。分鍾是整數值,範圍是0到59。
以下示例程序旨在說明getUTCMinutes()方法:
<script>
// Here a date has been assigned according to universal
// time while creating Date object
var dataobj = new Date('October 15, 1996 23:35:32 GMT+11:00');
// Minute from above date object is
// being extracted using getUTCMinutes().
var B = dataobj.getUTCMinutes();
// Printing minute according to universal time
document.write(B);
</script>
輸出:
35
錯誤和異常:
- 示例1:該月的日期應該在1到31之間,因為沒有一個月的日期大於31,這就是為什麽它返回NaN的原因,即不是一個數字,因為該月的日期不存在。如果月份日期不存在,則根據世界通用時間將不存在分鍾。
<script> // Here a date has been assigned according to universal // time while creating Date object. var dataobj = new Date('October 33, 1996 23:35:32 GMT+11:00'); // Minute from above data object is // being extracted using getUTCMinutes(). var B = dataobj.getUTCMinutes(); // Printing minute according to universal time. document.write(B); </script>
輸出:
NaN
- 示例2:如果在創建Date對象時未向Date()構造函數提供分鍾數,則getUTCMinutes()函數將根據通用時間返回零(0),這是一種例外情況。
<script> // Here a date has been assigned according to universal // time while creating Date object. var dataobj = new Date('October 13, 1996 GMT+11:00'); // Minute from above data object is // being extracted using getUTCMinutes(). var B = dataobj.getUTCMinutes(); // Printing minute according to universal time. document.write(B); </script>
輸出:
0
- 示例3:如果在創建Date對象時未向Date()構造函數提供任何參數,則getUTCMinutes()函數將根據通用時間返回當前分鍾。
<script> // Here nothing has been assigned according to universal // time while creating Date object. var dataobj = new Date(); // Minute from above data object is // being extracted using getUTCMinutes(). var B = dataobj.getUTCMinutes(); // Printing current minute // according to universal time. document.write(B); </script>
輸出:
18
應用程序:它具有許多應用程序,例如獲取當前分鍾。下麵的程序顯示了此函數的應用之一。它給出了當前的分鍾。
<script>
// Here nothing has been assigned according to universal
// time while creating a Date object.
var dataobj = new Date();
// Minute from above data object is
// being extracted using getUTCMinutes().
var B = dataobj.getUTCMinutes();
// Printing current minute
// according to universal time.
document.write(B);
</script>
輸出:
18
支持的瀏覽器:JavaScript date.getUTCMinutes()函數支持的瀏覽器如下:
- 穀歌瀏覽器
- IE瀏覽器
- 火狐瀏覽器
- Opera
- 蘋果瀏覽器
相關用法
- Javascript Math.pow( )用法及代碼示例
- Javascript Array some()用法及代碼示例
- Javascript Number()用法及代碼示例
- Javascript Symbol.for()用法及代碼示例
- Javascript toExponential()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Math.abs( )用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 JavaScript | date.getUTCMinutes() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。