JavaScript getSeconds() | Get the Seconds (0-59)

The JavaScript getSeconds() method is used to get the seconds (0-59) of the time. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let min = d.getSeconds();
      document.getElementById("xyz").innerHTML = min;
   </script>

</body>
</html>
Output

JavaScript getSeconds() Syntax

The syntax of getSeconds() method in JavaScript is:

x.getSeconds()

where x must be an object of the Date() constructor.

The getSeconds() method returns a number from 0 to 59 which will be the seconds of a date.

Please note: To display date in format dd-mm-yyyy, refer to its separate example.

Please note: To display time in format hh:mm:ss, refer to its separate example.

Please note: To display time in format hh:mm:ss AM/PM, refer to its separate example.

JavaScript Online Test


« Previous Tutorial Next Tutorial »