Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is getSeconds() in JavaScript?

Umme Ammara

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The getSeconds() method in JavaScript returns the seconds of the specified date and time.

Syntax

We declare the getSeconds() method as shown below:

Parameters and return value

The getSeconds() method does not take any parameters. Instead, it returns the numeric value (0 - 59) corresponding to the seconds for the specified date and time.

Examples

The following code shows the use of the getSeconds() method in JavaScript.

First, we declare a new Date object with the current date and time. We then use the getSeconds() method to get the seconds of the specified date and time:

//Date Object
var d = new Date();
//getSeconds() Method
var s = d.getSeconds();
//Display the year
console.log("Seconds:", s);

In the example below, we declare the new Date object with a specified date. Then, the getSeconds() method returns the corresponding seconds for this specified date:

//Date Object with a specified date
var d = new Date("May 25, 1999 15:15:15");
//getSeconds() Method
var s = d.getSeconds();
//Display
console.log("Seconds:", s);

RELATED TAGS

javascript

CONTRIBUTOR

Umme Ammara
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring