JavaScript Date getSeconds() method - JavaScript Tutorial

JavaScript Date getSeconds() method

BLUF: This tutorial on JavaScript Date getSeconds() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date getSeconds() method

Understanding JavaScript Date getSeconds() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience