JavaScript getSeconds Function

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>
JavaScript getSeconds Function Example

Date and Time: Sun Nov 04 2018 15:59:15 GMT+0530 (Indian Standard Time)
Seconds using getSeconds(): 15

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>
JavaScript getSeconds Function 2

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>
JavaScript getSeconds Function Example

Date and Time: Mon Jan 25 2016 00:00:00 GMT+0530 (Indian Standard Time)
Seconds using getSeconds(): 0