Method
JavaScript Date getSeconds() Method
The getSeconds() method of JavaScript’s Date object is used to get the seconds for the specified date according to local time.
Syntax
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
dateObj.getSeconds()
[/dm_code_snippet]
Parameters
No parameters are required for this method.
Return Value
The method returns the seconds (0-59) for the specified date according to local time.
Example
The following example shows the usage of the getSeconds() method.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Create a new date object var d = new Date(); // Get the seconds var n = d.getSeconds(); // Display the current seconds document.write("Current Seconds: " + n );
[/dm_code_snippet]
This will produce the following result:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
Current Seconds: 35
[/dm_code_snippet]
Browser Support
The getSeconds() method is supported in all major browsers.
Additional Notes
The getSeconds() method returns the seconds (0-59) for the specified date according to local time.
Remember that the Date object has methods to get and set the month, day, year, hour, minute, and second.