What is getSeconds() in JavaScript?
The getSeconds() method in JavaScript returns the seconds of the specified date and time.
Syntax
We declare the getSeconds() method as shown below:
Parameters and return value
The getSeconds() method does not take any parameters. Instead, it returns the numeric value (0 - 59) corresponding to the seconds for the specified date and time.
Examples
The following code shows the use of the getSeconds() method in JavaScript.
First, we declare a new Date object with the current date and time. We then use the getSeconds() method to get the seconds of the specified date and time:
//Date Objectvar d = new Date();//getSeconds() Methodvar s = d.getSeconds();//Display the yearconsole.log("Seconds:", s);
In the example below, we declare the new Date object with a specified date. Then, the getSeconds() method returns the corresponding seconds for this specified date:
//Date Object with a specified datevar d = new Date("May 25, 1999 15:15:15");//getSeconds() Methodvar s = d.getSeconds();//Displayconsole.log("Seconds:", s);
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved