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


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

JavaScript 日期 getSeconds() 方法

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

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

用法:

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

例子:

    Input:
    var dt = new Date();
    dt.getSeconds();
    
    Output:
    49 (if the time is any_hours:any_minutes:19)

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

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

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

輸出

Current seconds is:49



相關用法


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