JavaScript Date getSeconds() method

The getSeconds method in JavaScript retrieves the seconds from a given date, utilizing the local time setting.

Syntax

The syntax for the getSeconds method is delineated as follows:

Example

dateObj.getSeconds()

Return

A whole number ranging from 0 to 59 that denotes the second.

JavaScript Date getSeconds method example

In this section, we will explore the getSeconds method by examining several illustrative examples.

Example 1

Let’s examine an illustration that demonstrates how to display the current second’s value.

Example

<script>

var sec=new Date();

document.writeln(sec.getSeconds());

</script>

Output:

Example 2

Consider the following example that demonstrates how to extract and display the seconds from a specified date.

Example

<script>

var sec=new Date("August 15, 1947 20:22:10");

document.writeln(sec.getSeconds());

</script>

Output:

Input Required

This code uses input(). Please provide values below: