.getSeconds()
Published Jun 22, 2021Updated Jun 5, 2023
Contribute to Docs
Called from an instance of the Date
class, will return the seconds according to the local time.
Syntax
myDate.getSeconds();
The return value of getSeconds()
will only be an integer number between 0
and 59
, meaning seconds.
Example
To determine if the match has ended or still ongoing:
const today = new Date('June 25, 2021 13:41:50');if (today.getSeconds() > 50) {console.log('The match has ended.');} else {console.log('This match is still ongoing.');}// Output: This match is still ongoing.
Codebyte Example
The example below defines a new Date
object dateTimeNow
, and then saves the result of the getSeconds()
method in a new variable seconds
. Finally, the current date\time, the current seconds, and the seconds remaining in the current minute are logged to the console.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours