JavaScript getSeconds function is one of the Date Functions, which returns the total number of seconds on a given date. The following getSeconds function returns the number of seconds in the current date and time.
<!DOCTYPE html> <html> <head> <title> JS </title> </head> <body> <h1> Example </h1> <script> var dt = Date(); document.write("Date and Time : " + dt); document.write("Seconds : " + dt.getSeconds()); </script> </body> </html>
Example
Date and Time: Sun Nov 04 2018 15:59:15 GMT+0530 (Indian Standard Time)
Seconds : 15
getSeconds Example
In this example, we extract the total number of seconds from the custom date.
<!DOCTYPE html> <html> <head> <title> JavaScriptGetSecondsFunction </title> </head> <body> <h1> JavaScriptgetSecondsFunctionExample </h1> <script> var dt = Date("January 25, 2016 10:09:34"); document.write("Date and Time : " + dt); document.write("Seconds using getSeconds(): " + dt.getSeconds()); </script> </body> </html>

In this JavaScript get seconds example, we extract the seconds from the custom date without seconds (time). This will return 0 seconds.
<!DOCTYPE html> <html> <head> <title> JS </title> </head> <body> <h1> Example </h1> <script> var dt = Date("January 25, 2016"); document.write("DateTime : " + dt); document.write("Seconds : " + dt.getSeconds()); </script> </body> </html>
Example
DateTime: Mon Jan 25 2016 00:00:00 GMT+0530 (Indian Standard Time)
Seconds : 0