當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript Date getMinutes()用法及代碼示例

JavaScript 日期 getMinutes() 方法

getMinutes() 方法是 Date 的類方法,用於獲取當前時間的唯一分鍾數。

它不接受任何參數並返回 0 到 59 之間的值。

用法:

    var dt = new Date();
    dt.getMinutes();

例子:

    Input:
    var dt = new Date();
    dt.getMinutes();
    
    Output:
    18 (if the time is any_hour:18:any_seconds)

使用 getHours() 方法僅從當前時間獲取小時數的 JavaScript 代碼

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var minutes = dt.getMinutes(); //getting minutes from current time
	//printing minutes
	document.write("Current minutes is:" + minutes);
</script>
</body>
</html>

輸出

Current minutes is:18



相關用法


注:本文由純淨天空篩選整理自 Date getMinutes() method with example in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。