Home »
JavaScript
Date getSeconds() method with example in JavaScript
JavaScript Date getSeconds() method: Here, we are going to learn about the getSeconds() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 04, 2019
JavaScript Date getSeconds() method
getSeconds() method is a Date's class method and it is used to get the only seconds from the current time.
It accepts nothing as the parameter and returns a value between 0 to 59.
Syntax
var dt = new Date();
dt.getSeconds();
Sample Input/Output
Input:
var dt = new Date();
dt.getSeconds();
Output:
49 (if the time is any_hours:any_minutes:19)
JavaScript code to get the seconds only from the current time using getSeconds() method
<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>
Output
Current seconds is : 49
JavaScript Date Object Methods »