JavaScript getSeconds function is one of the Date Function, which returns the total number of seconds on a given date. The following JavaScript getSeconds function returns the number of seconds in the current date and time.
<!DOCTYPE html> <html> <head> <title> JavaScript Get Seconds Function </title> </head> <body> <h1> JavaScript getSeconds Function Example </h1> <script> var dt = Date(); document.write("Date and Time : " + dt); document.write("Seconds using getSeconds(): " + dt.getSeconds()); </script> </body> </html>
OUTPUT
JavaScript getSeconds Function Example
In this getSeconds function example, we are extracting the total number of seconds from the custom date
<!DOCTYPE html> <html> <head> <title> JavaScript Get Seconds Function </title> </head> <body> <h1> JavaScript getSeconds Function Example </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>
OUTPUT
JavaScript get Seconds Function Example
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> JavaScript Get Seconds Function </title> </head> <body> <h1> JavaScript getSeconds Function Example </h1> <script> var dt = Date("January 25, 2016"); document.write("Date and Time : " + dt); document.write("Seconds using getSeconds(): " + dt.getSeconds()); </script> </body> </html>
OUTPUT